Browse Source

I can't even count the changes 💀

master
j4ck 2 years ago
parent
commit
2b87d05e9e
  1. 25
      RSND/Core/Database.cs
  2. 7
      RSND/Core/DbClient.cs
  3. 2
      RSND/Core/Querying/Queries/CreateTableQuery.cs
  4. 8
      RSND/Core/Querying/Queries/GetQuery.cs
  5. 9
      RSND/Core/Querying/Queries/SetQuery.cs
  6. 3
      RSND/Core/Querying/Query.cs
  7. 1
      RSND/Core/Querying/QueryHelper.cs
  8. 1
      RSND/Core/Querying/QueryType.cs

25
RSND/Core/Database.cs

@ -23,6 +23,8 @@ public class Database
Console.WriteLine($"[{Name}] The file exists.");
var json = File.ReadAllText($"{Name}.json");
var db = JsonConvert.DeserializeObject<List<Table>>(json);
// if this is null, then something is wrong with the file
if (db != null)
_tables = db;
}
@ -61,7 +63,7 @@ public class Database
public string GetValue(GetQuery? query)
{
Console.WriteLine(_tables.Count.ToString().Pastel("#ff0000"));
var table = query?.Table;
var table = query?.TableName;
var where = query?.Where;
var split = where?.Split("|");
@ -72,11 +74,30 @@ public class Database
if (query?.Select != "*") return "";
var tableToReturn = _tables.Find(x => x.Name == table);
var rows = tableToReturn?.Rows?.Where(x => x.Columns?.FirstOrDefault(y => y.Name == colName)?.Value == value).ToArray();
var rows = tableToReturn?.Rows?.Where(x => x.Columns?.FirstOrDefault(y => y.Name == colName)?.Value == value)
.ToArray();
return JsonConvert.SerializeObject(rows);
}
public void SetValue(SetQuery? query)
{
var table = query?.TableName;
var key = query?.Key;
var value = query?.Value;
var newValue = query?.NewValue;
Console.WriteLine(table);
var tableToReturn = _tables.Find(x => x.Name == table);
Console.WriteLine(tableToReturn == null ? "shits null" : "shits not null");
Console.WriteLine(key);
var row = tableToReturn?.Rows?.FirstOrDefault(x => x.Columns?.FirstOrDefault(y => y.Name == key)?.Value == value);
var column = row?.Columns?.FirstOrDefault(x => x.Name == key);
column.Value = newValue;
Console.WriteLine(column.Value);
}
public static void Loop()
{
while (true)

7
RSND/Core/DbClient.cs

@ -50,7 +50,12 @@ public class DbClient
Console.WriteLine($"Sent: {queryResult}".Pastel("#71C562"));
break;
}
case QueryType.SetValue:
{
SetQuery setQuery = JsonConvert.DeserializeObject<SetQuery>(query);
RsndMain.Db.SetValue(setQuery);
break;
}
case QueryType.CreateTable:
{
CreateTableQuery createTableQuery = JsonConvert.DeserializeObject<CreateTableQuery>(query);

2
RSND/Core/Querying/Queries/CreateTableQuery.cs

@ -2,7 +2,7 @@
namespace RSND.Core.Querying.Queries;
public class CreateTableQuery : IQuery
public class CreateTableQuery : Query
{
public CreateTableQuery(string tableName, Row[] rows)
{

8
RSND/Core/Querying/Queries/GetQuery.cs

@ -1,15 +1,15 @@
namespace RSND.Core.Querying.Queries;
public class GetQuery : IQuery
public class GetQuery : Query
{
public GetQuery(string table, string select, string where)
public GetQuery(string tableName, string select, string where)
{
Table = table;
TableName = tableName;
Select = select;
Where = where;
}
public string Table { get; set; }
public string TableName { get; set; }
public string Select { get; set; }
public string Where { get; set; }
}

9
RSND/Core/Querying/Queries/SetQuery.cs

@ -0,0 +1,9 @@
namespace RSND.Core.Querying.Queries;
public class SetQuery : Query
{
public string TableName { get; set; }
public string Key { get; set; }
public string Value { get; set; }
public string NewValue { get; set; }
}

3
RSND/Core/Querying/IQuery.cs → RSND/Core/Querying/Query.cs

@ -1,6 +1,5 @@
namespace RSND.Core.Querying;
public interface IQuery
public abstract class Query
{
}

1
RSND/Core/Querying/QueryHelper.cs

@ -13,6 +13,7 @@ public static class QueryHelper
return query.Type switch
{
"GetValue" => QueryType.GetValue,
"SetValue" => QueryType.SetValue,
"CreateTable" => QueryType.CreateTable,
_ => null
};

1
RSND/Core/Querying/QueryType.cs

@ -3,5 +3,6 @@
public enum QueryType
{
GetValue,
SetValue,
CreateTable
}
Loading…
Cancel
Save