From b1524d245e193d4803215145c7fac1dad673a823 Mon Sep 17 00:00:00 2001 From: Selfhost Alt Date: Thu, 14 Sep 2023 22:52:43 -0700 Subject: [PATCH] Add ability to enable DEV logs of Sqlite queries --- server/Database.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index a959d0a9..09f6dfc7 100644 --- a/server/Database.js +++ b/server/Database.js @@ -166,10 +166,25 @@ class Database { */ async connect() { Logger.info(`[Database] Initializing db at "${this.dbPath}"`) + + let logging = false; + let benchmark = false; + if (process.env.QUERY_LOGGING === "log") { + // Setting QUERY_LOGGING=log will log all Sequelize queries before they run + Logger.info(`[Database] Query logging enabled"`) + logging = (query) => Logger.dev(`Running the following query: ${query}`) + } else if (process.env.QUERY_LOGGING === "benchmark") { + // Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run + Logger.info(`[Database] Query benchmarking enabled"`) + logging = (query, time) => Logger.dev(`Ran the following query in ${time}ms: ${query}`) + benchmark = true; + } + this.sequelize = new Sequelize({ dialect: 'sqlite', storage: this.dbPath, - logging: false, + logging: logging, + benchmark: benchmark, transactionType: 'IMMEDIATE' })