using App41.Models;
using SQLite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace App
{
public class SQLiteHelper
{
public string connstr = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "User.db");
public SQLiteConnection db;
public SQLiteHelper()
{
db = new SQLiteConnection(connstr);
db.CreateTable<Item>();
}
public int Add<T>(T model) where T : BaseModel
{
return db.Insert(model);
}
public int Update<T>(T model) where T : BaseModel
{
return db.Update(model);
}
public int Delete<T>(T model) where T : BaseModel
{
return db.Update(model);
}
public List<T> Query<T>() where T : BaseModel, new()
{
return db.Table<T>().ToList();
}
public T Query<T>(int id) where T : BaseModel, new()
{
return db.Table<T>().Where(x=>x.Id == id).FirstOrDefault();
}
public int Execute(string sql)
{
return db.Execute(sql);
}
}
public class BaseModel
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
}
}