Exemplo n.º 1
0
        public void Save(SerializedModel model)
        {
            SerializedModel value = storage[model.Name].Find(
                (SerializedModel item) => item?.Id == model.Id
                );

            value.Data = model.Data;
        }
Exemplo n.º 2
0
        public void Save(SerializedModel model)
        {
            string update = CommandString.Update(
                model: model.Name,
                id: model.Id,
                fields: model.Data);

            Command(update);
        }
Exemplo n.º 3
0
        public int Create(SerializedModel model)
        {
            string name = model.Name;
            int    id   = GetId(name);

            string insert = CommandString.InsertInto(
                model: name,
                id: id,
                fields: model.Data);

            Command(insert);

            return(id);
        }
Exemplo n.º 4
0
        private static SerializedModel ReadRow(SQLiteDataReader reader, string model)
        {
            SerializedModel result = new SerializedModel();

            Dictionary <string, object> data = new Dictionary <string, object>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                string name = reader.GetName(i);
                if (name == "Id")
                {
                    result.Id = reader.GetInt32(i);
                    continue;
                }

                data[name] = reader.GetValue(i);
            }

            result.Name = model;
            result.Data = data;

            return(result);
        }
Exemplo n.º 5
0
        public SerializedModel GetById(string model, int id)
        {
            SerializedModel result = storage[model].Find((SerializedModel item) => item?.Id == id);

            return(result ?? throw new Exception("Attempt to get removed or non-existing value"));
        }
Exemplo n.º 6
0
 public int Create(SerializedModel model)
 {
     model.Id = storage[model.Name].Count;
     storage[model.Name].Add(model);
     return(model.Id);
 }