From dfc5f4ed8f7f2f62eb997792b8ad1d76616f6a89 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 21 Jan 2022 10:52:25 +0100 Subject: [PATCH] [bug] hopefully fix SQLITE_BUSY --- server/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/index.js b/server/index.js index 977dbf97..7a72857a 100644 --- a/server/index.js +++ b/server/index.js @@ -39,17 +39,22 @@ class LazyDatabase { this.db = null; } - async get(...args) { + async init() { if (this.db === null) { this.db = await dbConnection(); + await this.db.get('PRAGMA journal_mode = WAL;'); + await this.db.get('PRAGMA busy_timeout = 5000;'); + await this.db.get('PRAGMA foreign_keys = ON;') } + } + + async get(...args) { + await this.init(); return this.db.get(...args) } async all(...args) { - if (this.db === null) { - this.db = await dbConnection(); - } + await this.init(); return this.db.all(...args); }