You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SQLite;
|
|
|
|
|
|
|
|
|
|
namespace Justice.Helpers
|
|
|
|
|
{
|
|
|
|
|
public class DatabaseHelper
|
|
|
|
|
{
|
|
|
|
|
private readonly SQLiteAsyncConnection _database;
|
|
|
|
|
public DatabaseHelper(string databaseName = "Appdatabase.db")
|
|
|
|
|
{
|
|
|
|
|
var dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), databaseName);
|
|
|
|
|
_database = new SQLiteAsyncConnection(dbPath);
|
|
|
|
|
}
|
|
|
|
|
public async Task InitializeAsync<T>() where T: new()
|
|
|
|
|
{
|
|
|
|
|
await _database.CreateTableAsync<T>();
|
|
|
|
|
}
|
|
|
|
|
public async Task<int> InsertAsync<T>(T item) where T : new()
|
|
|
|
|
{
|
|
|
|
|
return await _database.InsertAsync(item);
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>>GetAllAsync<T>()where T : new()
|
|
|
|
|
{
|
|
|
|
|
return await _database.Table<T>().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<List<T>> GetAsync<T>(Expression<Func<T, bool>> predicate) where T : new()
|
|
|
|
|
{
|
|
|
|
|
return await _database.Table<T>().Where(predicate).ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
public async Task<int> UpdateAsync<T>(T item) where T : new()
|
|
|
|
|
{
|
|
|
|
|
return await _database.UpdateAsync(item);
|
|
|
|
|
}
|
|
|
|
|
public async Task<int> DeleteAsync<T>(T item) where T : new()
|
|
|
|
|
{
|
|
|
|
|
return await _database.DeleteAsync(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|