Esempio n. 1
0
 public string Delete(string Json)
 {
     try
     {
         string        TableName = JsonAdapter.TableNameFromJson(Json);
         List <Packet> packets   = PackageAdapter.PacketsFromJson(Json);
         string        Condition = FilterAdapter.GetCondition(TableName, packets.ToArray());
         string        sql       = $"DELETE FROM \"{TableName}\" WHERE {Condition}";
         return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(sql)));
     }
     catch (Exception ex)
     {
         return(new JObject().AddStatus(ex).ToString());
     }
 }
Esempio n. 2
0
 public string Add(string Json)
 {
     try
     {
         List <Entity> entities = JsonAdapter.AdaptEntityFromJson(Json);
         foreach (Entity item in entities)
         {
             string Sql = RowCollector.Insert(item, NpgController);
             NpgController.InvokeQuery(Sql);
         }
         return(new JObject().AddStatus("Success").ToString());
     }
     catch (Exception ex)
     {
         return(new JObject().AddStatus(ex).ToString());
     }
 }
Esempio n. 3
0
        public string GetAll(string Json)
        {
            try
            {
                LimitPacket packet = GetLimit(ref Json);
                string      limit  = packet == null ? "" : $" {LimitAdapter.AdaptToSql(packet)}";

                string TableName = JsonAdapter.TableNameFromJson(Json);
                string Sql       = $"SELECT * FROM \"{TableName}\"{limit}";

                return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(Sql)));
            }
            catch (Exception ex)
            {
                return(new JObject().AddStatus(ex).ToString());
            }
        }
Esempio n. 4
0
        public string Update(string Json)
        {
            try
            {
                string TableName = JsonAdapter.TableNameFromJson(Json);

                List <Packet> packets   = PackageAdapter.PacketsFromJson(Json);
                string        Condition = FilterAdapter.GetCondition(TableName, packets.ToArray());

                List <UpdatePacket> updatePackets = SetConverter.FromJson(Json);
                string Sets = RowCollector.Set(updatePackets);

                string Sql = $"UPDATE \"{TableName}\" {Sets} WHERE {Condition}";
                return(JsonAdapter.ResultToJson(NpgController.InvokeQuery(Sql)));
            }
            catch (Exception ex)
            {
                return(new JObject().AddStatus(ex).ToString());
            }
        }
Esempio n. 5
0
        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());
            }
        }