lib/cli/create_db: make WAL mode optional

This commit is contained in:
2025-05-16 17:05:59 +02:00
parent 4407c06f12
commit 42db69e57a
2 changed files with 15 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ Future<Database> 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<Database> 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,

View File

@@ -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<void> run() async {
@@ -22,6 +32,7 @@ class CreateDb extends Command {
final db = await openLocalDb(
libsqlitePath: argResults!.option('libsqlite')!,
walMode: argResults!.flag('wal'),
readWrite: true,
);