share db
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user