diff --git a/lib/_data_ingestion/open_local_db.dart b/lib/_data_ingestion/open_local_db.dart index 349d8a8..a1f89cb 100644 --- a/lib/_data_ingestion/open_local_db.dart +++ b/lib/_data_ingestion/open_local_db.dart @@ -13,6 +13,7 @@ Future openLocalDb({ String? jadbPath, bool readWrite = false, bool assertTablesExist = true, + bool walMode = false, }) async { libsqlitePath ??= Platform.environment['LIBSQLITE_PATH']; jadbPath ??= Platform.environment['JADB_PATH']; @@ -42,7 +43,9 @@ Future openLocalDb({ jadbPath, options: OpenDatabaseOptions( onConfigure: (db) async { - await db.execute("PRAGMA journal_mode = WAL"); + if (walMode) { + await db.execute("PRAGMA journal_mode = WAL"); + } await db.execute("PRAGMA foreign_keys = ON"); }, readOnly: !readWrite, diff --git a/lib/cli/commands/create_db.dart b/lib/cli/commands/create_db.dart index 93861b9..8d6391d 100644 --- a/lib/cli/commands/create_db.dart +++ b/lib/cli/commands/create_db.dart @@ -12,6 +12,16 @@ class CreateDb extends Command { CreateDb() { addLibsqliteArg(argParser); + argParser.addFlag( + 'wal', + help: + '''Whether to use Write-Ahead Logging (WAL) mode. + + This is recommended for better performance, but may not be used with + the readonly NixOS store. + ''', + defaultsTo: false, + ); } Future run() async { @@ -22,6 +32,7 @@ class CreateDb extends Command { final db = await openLocalDb( libsqlitePath: argResults!.option('libsqlite')!, + walMode: argResults!.flag('wal'), readWrite: true, );