Esempio n. 1
0
        public SerializedModel[] GetAll(string model)
        {
            string query = CommandString.SelectAll(model);

            SQLiteDataReader reader = Read(query);

            return(ReadData(reader, model));
        }
Esempio n. 2
0
        public SerializedModel GetById(string model, int id)
        {
            string query = CommandString.SelectById(model, id);

            SQLiteDataReader reader = Read(query);

            return(ReadData(reader, model)[0]);
        }
Esempio n. 3
0
        public void AddModel <T>() where T : Model <T>
        {
            string name = Model <T> .ModelName;
            Dictionary <string, Type> fields = Model <T> .GetFields();

            string createTable = CommandString.CreateTable(name, fields);

            Command(createTable);
        }
Esempio n. 4
0
        public void Save(SerializedModel model)
        {
            string update = CommandString.Update(
                model: model.Name,
                id: model.Id,
                fields: model.Data);

            Command(update);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private int GetId(string model)
        {
            string query = CommandString.SelectMaxId(model);

            SQLiteDataReader reader = Read(query);

            if (!reader.HasRows)
            {
                return(-1);
            }

            reader.Read();

            try
            {
                return(reader.GetInt32(0) + 1);
            } catch
            {
                return(0);
            }
        }
Esempio n. 7
0
        public void Remove(string model, int id)
        {
            string remove = CommandString.RemoveById(model, id);

            Command(remove);
        }