Fix: Start using sqlite module that actually uses promises.

For now export legacy sqlite3 module until other code is refactored.
This commit is contained in:
baldo 2019-03-29 22:26:54 +01:00
parent 2beab45f32
commit 2e27e63f94
3 changed files with 28 additions and 2 deletions

15
package-lock.json generated
View file

@ -8089,6 +8089,21 @@
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==", "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==",
"dev": true "dev": true
}, },
"sql-template-strings": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/sql-template-strings/-/sql-template-strings-2.2.2.tgz",
"integrity": "sha1-PxFQiiWt384hejBCqdMAwxk7lv8=",
"optional": true
},
"sqlite": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/sqlite/-/sqlite-3.0.3.tgz",
"integrity": "sha512-DpofdtBibbiOObtdADGZYE6bvnLpjRG4ut/MDTDau2nK40htOLj1E0c55aOkvbnRVqQ0ZPtjj7PJuKKyS0Ypww==",
"requires": {
"sql-template-strings": "^2.2.2",
"sqlite3": "^4.0.0"
}
},
"sqlite3": { "sqlite3": {
"version": "4.0.6", "version": "4.0.6",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.6.tgz", "resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.6.tgz",

View file

@ -39,6 +39,7 @@
"request": "^2.88.0", "request": "^2.88.0",
"scribe-js": "^2.0.4", "scribe-js": "^2.0.4",
"serve-static": "^1.13.2", "serve-static": "^1.13.2",
"sqlite": "^3.0.3",
"sqlite3": "^4.0.2" "sqlite3": "^4.0.2"
}, },
"devDependencies": { "devDependencies": {

View file

@ -48,6 +48,7 @@ async function applyMigrations(db) {
} }
async function init() { async function init() {
const sqlite = require('sqlite');
const SQLite3 = require('sqlite3'); const SQLite3 = require('sqlite3');
const file = config.server.databaseFile; const file = config.server.databaseFile;
@ -55,7 +56,7 @@ async function init() {
let db; let db;
try { try {
db = new SQLite3.Database(file); db = await sqlite.open(file);
} }
catch (error) { catch (error) {
Logger.tag('database').error('Error initialzing database:', error); Logger.tag('database').error('Error initialzing database:', error);
@ -72,7 +73,16 @@ async function init() {
throw error; throw error;
} }
module.exports.db = db; let legacyDB;
try {
legacyDB = new SQLite3.Database(file);
}
catch (error) {
Logger.tag('database').error('Error initialzing legacy database lib:', error);
throw error;
}
module.exports.db = legacyDB;
} }
module.exports = { module.exports = {