From 08a742c02d372af5b78c1370b0ec46cf45f89285 Mon Sep 17 00:00:00 2001 From: Uwe <13865709+greenrobot-team@users.noreply.github.com> Date: Wed, 22 May 2024 06:43:50 +0200 Subject: [PATCH] sqflite: enable WAL on Android https://github.com/objectbox/objectbox-dart-performance/issues/9 --- lib/sqf_executor.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/sqf_executor.dart b/lib/sqf_executor.dart index 66c367b..9d7d836 100644 --- a/lib/sqf_executor.dart +++ b/lib/sqf_executor.dart @@ -16,9 +16,17 @@ abstract class Executor extends ExecutorBase { : super(tracker); static Future createDatabase( - Directory dbDir, String table, bool withIndexes) { - return openDatabase(dbDir.path, version: 1, - onCreate: (Database db, int version) async { + Directory dbDir, String table, bool withIndexes) async { + // Debug logging + // https://github.com/tekartik/sqflite/blob/master/sqflite/doc/dev_tips.md#debugging + // await databaseFactory.debugSetLogLevel(sqfliteLogLevelVerbose); + + return openDatabase(dbDir.path, version: 1, onConfigure: (db) async { + // Make sure WAL is enabled on Android + // With debug logs on, should print "PRAGMA journal_mode=WAL" + // https://github.com/tekartik/sqflite/blob/master/sqflite/doc/dev_tips.md#enable-wal-on-android + await db.rawQuery('PRAGMA journal_mode=WAL'); + }, onCreate: (Database db, int version) async { await db.execute(''' CREATE TABLE $table ( id integer primary key autoincrement,