From 9fed12cf87303135848d4202c2c1f2af68246a34 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 10 Dec 2023 22:08:45 +0900 Subject: [PATCH] db: Revert 'revert of #252' --- lib/database/database.dart | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/database/database.dart b/lib/database/database.dart index d147bb3b9..80a7c6101 100644 --- a/lib/database/database.dart +++ b/lib/database/database.dart @@ -21,9 +21,10 @@ class DataBaseManager { @protected @mustCallSuper - void dispose() async { + Future dispose() async { print('close: ${dbPath!}'); - if (db != null) db!.close(); + await db?.close(); + db = null; } static Future getInstance() async { @@ -43,20 +44,17 @@ class DataBaseManager { } static Future 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 open() async { db ??= await openDatabase(dbPath!); } - Future checkOpen() async { - if(db != null){ - if (!db!.isOpen) db = await openDatabase(dbPath!); - } else if(db == null){ + Future checkOpen() async { + if (!(db?.isOpen ?? false)) { db = await openDatabase(dbPath!); } }