public string Adapt(string Json) { string MainTable = JsonAdapter.TableNameFromJson(Json); string TableName = ""; List <Packet> packets = PackageAdapter.PacketsONFromJson(Json); PackageAdapter.Normalize(ref packets); packets = SetTableName(MainTable, packets.ToArray()); try { TableName = $"{GetTableNameFromPackets(packets.ToArray())}"; } catch (Exception ex) { throw ex; } string condition = new FilterAdapter().GetOnCondition(TableName, packets.ToArray()); string Sql = $"INNER JOIN {TableName} ON {condition}"; return(Sql); }
public string Where(string Json) { Validators.CheckPackets check = new Validators.CheckPackets(); try { LimitPacket limitPacket = GetLimit(ref Json); string limit = limitPacket == null ? "" : $" {LimitAdapter.AdaptToSql(limitPacket)}"; OrderByPacket orderByPacket = GetOrderBy(ref Json); string OrderBy = orderByPacket == null ? "" : $" {OrderByAdapter.ToSql(orderByPacket)}"; if (check.CheckJoin(Json)) { string Condition = ""; Joining.JoinAdapter adapter = new Joining.JoinAdapter(); string TableName = JsonAdapter.TableNameFromJson(Json); if (check.CheckPacket(Json)) { List <Packet> packets = PackageAdapter.PacketsFromJson(Json); PackageAdapter.Normalize(ref packets); Condition = $"WHERE {FilterAdapter.GetCondition(TableName, packets.ToArray())}"; } string JoinCondition = adapter.Adapt(Json); string sql = $"SELECT * FROM \"{TableName}\" {JoinCondition} {Condition}{OrderBy}{limit}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } else { string TableName = JsonAdapter.TableNameFromJson(Json); List <Packet> packets = PackageAdapter.PacketsFromJson(Json); string Condition = FilterAdapter.GetCondition(TableName, packets.ToArray()); string sql = $"SELECT * FROM \"{TableName}\" WHERE {Condition}{OrderBy}{limit}"; return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql))); } } catch (Exception ex) { return(new JObject().AddStatus(ex).ToString()); } }