Skip to content

Commit

Permalink
Merge pull request #252 from sliverappbar/db
Browse files Browse the repository at this point in the history
db: fix database manager for proper initial database downloading
  • Loading branch information
violet-dev authored Nov 11, 2023
2 parents ff5ff2e + ea8f6ba commit a2c3f8f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class DataBaseManager {

@protected
@mustCallSuper
void dispose() async {
Future<void> dispose() async {
print('close: ${dbPath!}');
if (db != null) db!.close();
await db?.close();
db = null;
}

static Future<DataBaseManager> getInstance() async {
Expand All @@ -37,18 +38,19 @@ class DataBaseManager {
}

static Future<void> reloadInstance() async {
var dbPath = Platform.isAndroid
? '${(await getApplicationDocumentsDirectory()).path}/data/data.db'
: '${await getDatabasesPath()}/data.db';
_instance = create(dbPath);
final db = _instance?.db;
_instance?.db = null;
await db?.close();
}

Future open() async {
Future<void> open() async {
db ??= await openDatabase(dbPath!);
}

Future checkOpen() async {
if (!db!.isOpen) db = await openDatabase(dbPath!);
Future<void> checkOpen() async {
if (!(db?.isOpen ?? false)) {
db = await openDatabase(dbPath!);
}
}

Future<List<Map<String, dynamic>>> query(String str) async {
Expand Down

0 comments on commit a2c3f8f

Please sign in to comment.