RSND/RSND/Core/Database.cs

47 lines
1.1 KiB
C#
Raw Normal View History

2022-06-01 22:24:42 +00:00
using Newtonsoft.Json;
using RSND.Core.DbInternals;
using RSND.Core.Querying.Queries;
namespace RSND.Core;
public class Database
{
List<Table> tables = new();
public void CreateTable(Table table)
{
tables.Add(table);
}
private static string GetRowsJson(Row[]? rows)
{
return JsonConvert.SerializeObject(new { Rows = rows });
}
public string GetValue(GetQuery? query)
{
Console.WriteLine(tables.Count);
var table = query?.Table;
var where = query?.Where;
var split = where?.Split("|");
var colName = split?[0];
var condition = split?[1];
var param = split?[2];
if (query?.Select != "*") return "";
var tableToReturn = tables.Find(x => x.Name == table);
var rows = tableToReturn?.Rows?.Where(x => x.Columns.FirstOrDefault(y => y.Data.Key == colName)?.Data.Value == param).ToArray();
return GetRowsJson(rows);
}
public static void Loop()
{
while (true)
{
}
}
}