This commit is contained in:
j4ck 2022-06-03 22:38:24 +03:00
parent 2b87d05e9e
commit 76898f89c3
4 changed files with 9 additions and 15 deletions

View File

@ -62,14 +62,10 @@ public class Database
public string GetValue(GetQuery? query) public string GetValue(GetQuery? query)
{ {
Console.WriteLine(_tables.Count.ToString().Pastel("#ff0000"));
var table = query?.TableName; var table = query?.TableName;
var where = query?.Where;
var split = where?.Split("|"); var colName = query?.Key;
var colName = split?[0]; var value = query?.Value;
var condition = split?[1];
var value = split?[2];
if (query?.Select != "*") return ""; if (query?.Select != "*") return "";
@ -87,15 +83,12 @@ public class Database
var value = query?.Value; var value = query?.Value;
var newValue = query?.NewValue; var newValue = query?.NewValue;
Console.WriteLine(table);
var tableToReturn = _tables.Find(x => x.Name == 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 row = tableToReturn?.Rows?.FirstOrDefault(x => x.Columns?.FirstOrDefault(y => y.Name == key)?.Value == value);
var column = row?.Columns?.FirstOrDefault(x => x.Name == key); var column = row?.Columns?.FirstOrDefault(x => x.Name == key);
column.Value = newValue; column.Value = newValue;
Console.WriteLine(column.Value); Save();
} }
public static void Loop() public static void Loop()

View File

@ -47,7 +47,6 @@ public class DbClient
GetQuery getQuery = JsonConvert.DeserializeObject<GetQuery>(query); GetQuery getQuery = JsonConvert.DeserializeObject<GetQuery>(query);
var queryResult = RsndMain.Db.GetValue(getQuery); var queryResult = RsndMain.Db.GetValue(getQuery);
_socket.Send(queryResult); _socket.Send(queryResult);
Console.WriteLine($"Sent: {queryResult}".Pastel("#71C562"));
break; break;
} }
case QueryType.SetValue: case QueryType.SetValue:

View File

@ -2,14 +2,16 @@
public class GetQuery : Query public class GetQuery : Query
{ {
public GetQuery(string tableName, string select, string where) public GetQuery(string tableName, string select, string key, string value)
{ {
TableName = tableName; TableName = tableName;
Select = select; Select = select;
Where = where; Key = key;
Value = value;
} }
public string TableName { get; set; } public string TableName { get; set; }
public string Select { get; set; } public string Select { get; set; }
public string Where { get; set; } public string Key { get; set; }
public string Value { get; set; }
} }

View File

@ -13,7 +13,7 @@ public static class RsndMain
Db.Save(); Db.Save();
WebSocketServer server = new WebSocketServer("ws://0.0.0.0:7878"); WebSocketServer server = new WebSocketServer("ws://0.0.0.0:7878");
Console.WriteLine("Server started");
FleckLog.Level = LogLevel.Error; FleckLog.Level = LogLevel.Error;
server.Start(socket => server.Start(socket =>