Skip to content

Commit 095352d

Browse files
authored
fix database open (#1476)
1 parent c2003ce commit 095352d

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

lib/db/util/open_database.dart

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ import 'package:sqlite3/sqlite3.dart';
1313
import '../../utils/file.dart';
1414
import '../custom_sqlite3_database.dart';
1515

16-
QueryExecutor _openDatabase(File file) {
17-
// Create the parent directory if it doesn't exist. sqlite will emit
18-
// confusing misuse warnings otherwise
19-
final dir = file.parent;
20-
if (!dir.existsSync()) {
21-
dir.createSync(recursive: true);
22-
}
23-
24-
final db = sqlite3.open(file.path);
25-
return NativeDatabase.opened(
26-
DatabaseProfiler(db, explain: kDebugMode),
27-
setup: (rawDb) {
28-
rawDb
29-
..execute('PRAGMA journal_mode=WAL;')
30-
..execute('PRAGMA foreign_keys=ON;')
31-
..execute('PRAGMA synchronous=NORMAL;');
32-
},
33-
);
34-
}
16+
QueryExecutor _openDatabase(File file) => LazyDatabase(() {
17+
// Create the parent directory if it doesn't exist. sqlite will emit
18+
// confusing misuse warnings otherwise
19+
final dir = file.parent;
20+
if (!dir.existsSync()) {
21+
dir.createSync(recursive: true);
22+
}
23+
final db = sqlite3.open(file.path);
24+
return NativeDatabase.opened(
25+
DatabaseProfiler(db, explain: kDebugMode),
26+
setup: (rawDb) {
27+
rawDb
28+
..execute('PRAGMA journal_mode=WAL;')
29+
..execute('PRAGMA foreign_keys=ON;')
30+
..execute('PRAGMA synchronous=NORMAL;');
31+
},
32+
);
33+
});
3534

3635
/// Connect to the database.
3736
Future<QueryExecutor> openQueryExecutor({

0 commit comments

Comments
 (0)