From dbecdac7fdf557019d32e2542ad0a132926034ef Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 14 Jun 2024 11:29:58 -0700 Subject: [PATCH] sqlite sets configurable busy_timeout, does immediate transactions --- lib/sqlite-creator.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sqlite-creator.js b/lib/sqlite-creator.js index 43a2449..f1cc171 100644 --- a/lib/sqlite-creator.js +++ b/lib/sqlite-creator.js @@ -43,6 +43,7 @@ const SQLiteCreator = (Abstract) => { * @param {object} options.db db options * @param {string} options.db.connectionString db connection string * @param {string=} options.db.queryLogLevel db query log level + * @param {number=} options.db.sqliteBusyTimeoutMs busy timeout * @param {bigint=} options.db.sqliteOptimizeAfterChanges optimize db after this many changes */ constructor(logger, options) { @@ -65,6 +66,8 @@ const SQLiteCreator = (Abstract) => { this.optimizeAfterChanges = options.db.sqliteOptimizeAfterChanges || 0; // Default to no periodic optimization. this.db.pragma('foreign_keys = on'); // Enforce consistency. this.db.pragma('journal_mode = WAL'); // Be faster, expect local filesystem. + const busyTimeout = options.db.sqliteBusyTimeoutMs || 5000; + this.db.pragma(`busy_timeout = ${busyTimeout}`); // Don't immediately fall over when busy. this.db.defaultSafeIntegers(true); // This probably isn't necessary, but by using these BigInts we keep weird floats out of the query logs. } @@ -93,7 +96,7 @@ const SQLiteCreator = (Abstract) => { * @returns {string} sql */ _createMetaVersionTable() { - return this.db.exec(`BEGIN; + return this.db.exec(`BEGIN IMMEDIATE; CREATE TABLE _meta_schema_version ( major INTEGER NOT NULL CHECK (typeof(major) = 'integer'), minor INTEGER NOT NULL CHECK (typeof(minor) = 'integer'), @@ -279,7 +282,7 @@ COMMIT;`); transaction(dbCtx, fn) { dbCtx = dbCtx || this.db; - return dbCtx.transaction(fn)(); + return dbCtx.transaction(fn).immediate(); } -- 2.49.0