@@ -4,7 +4,13 @@ import 'package:drift/drift.dart';
44import 'package:drift/native.dart' ;
55import 'package:path/path.dart' show join;
66
7- DatabaseConnection createAppDatabaseConnection (String ? path, String name, {bool logStatements = false }) {
7+ DatabaseConnection createAppDatabaseConnection (
8+ String ? path,
9+ String name, {
10+ bool logStatements = false ,
11+ bool isWalEnabled = true ,
12+ int ? busyTimeoutMilliseconds = 5000 ,
13+ }) {
814 return DatabaseConnection .delayed (
915 Future .sync (() async {
1016 final databasePath = join (path ?? '' , name);
@@ -15,15 +21,14 @@ DatabaseConnection createAppDatabaseConnection(String? path, String name, {bool
1521 setup: (database) {
1622 // Enables Write-Ahead Logging (WAL) mode.
1723 // In default mode (DELETE journal), readers block writers and writers block readers.
18- // WAL allows simultaneous readers and writers, which is crucial for
19- // concurrent access from the UI isolate and Background isolate.
20- database. execute ( 'PRAGMA journal_mode=WAL;' );
24+ if (isWalEnabled) {
25+ database. execute ( 'PRAGMA journal_mode=WAL;' );
26+ }
2127
2228 // Sets a timeout (in milliseconds) for waiting when the database is locked.
23- // By default, SQLite throws an error immediately if the DB is busy (SQLITE_BUSY).
24- // Setting a timeout allows the driver to automatically retry the operation
25- // for up to 5 seconds before failing, handling short-lived locks gracefully.
26- database.execute ('PRAGMA busy_timeout=5000;' );
29+ if (busyTimeoutMilliseconds != null ) {
30+ database.execute ('PRAGMA busy_timeout=$busyTimeoutMilliseconds ;' );
31+ }
2732 },
2833 );
2934
0 commit comments