The DB was moved to a different file and was returning a reference of the DB. When uploading a new database the original variable containing the DB in the DB file was not updating. Added setters and getters.
29 lines
546 B
JavaScript
29 lines
546 B
JavaScript
const Database = require("better-sqlite3");
|
|
const logger = require("../utils/logger.util");
|
|
const db_conf = require("../config/db.conf");
|
|
|
|
var db;
|
|
|
|
function connect() {
|
|
try {
|
|
logger.info("Connecting to Database...");
|
|
db = new Database(db_conf.path, { fileMustExist: true });
|
|
logger.info("Connected to Database.");
|
|
} catch (error) {
|
|
logger.error(error.message);
|
|
}
|
|
}
|
|
|
|
function getDB() {
|
|
return db;
|
|
}
|
|
|
|
function setDB(newDb) {
|
|
db = newDb;
|
|
}
|
|
|
|
module.exports = {
|
|
connect,
|
|
getDB,
|
|
setDB,
|
|
}; |