* @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) {
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.
}
* @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'),
transaction(dbCtx, fn) {
dbCtx = dbCtx || this.db;
- return dbCtx.transaction(fn)();
+ return dbCtx.transaction(fn).immediate();
}