This commit is contained in:
gaoyuan
2022-03-11 22:25:31 +08:00
parent 6d2e0624ab
commit 51ac42b9fc
14 changed files with 134 additions and 19 deletions

View File

@ -14,11 +14,32 @@ namespace Billing.Store
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
public static readonly string CacheFolder = FileSystem.CacheDirectory;
public static string DatabasePath => Path.Combine(PersonalFolder, dbfile);
#region Sqlite3
private const string dbfile = "data.db3";
private static SQLiteAsyncConnection database;
#endregion
public static async Task<bool> ReloadDatabase(string file)
{
var path = DatabasePath;
if (string.Equals(file, path, StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (database != null)
{
await database.CloseAsync();
}
File.Copy(file, path, true);
database = new SQLiteAsyncConnection(path,
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache);
return true;
}
private static readonly AsyncLazy<StoreHelper> Instance = new(async () =>
{
var instance = new StoreHelper();
@ -114,10 +135,13 @@ namespace Billing.Store
private StoreHelper()
{
database = new SQLiteAsyncConnection(Path.Combine(PersonalFolder, dbfile),
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache);
if (database == null)
{
database = new SQLiteAsyncConnection(DatabasePath,
SQLiteOpenFlags.ReadWrite |
SQLiteOpenFlags.Create |
SQLiteOpenFlags.SharedCache);
}
}
public Task<List<T>> GetListAsync<T>(string query, params object[] args) where T : new()