Skip to content

Commit

Permalink
Merge pull request advplyr#2102 from selfhost-alt/sqlite-query-logging
Browse files Browse the repository at this point in the history
Add ability to enable DEV logs of Sqlite queries
  • Loading branch information
advplyr authored Sep 22, 2023
2 parents a11fc21 + 1ab34fa commit 97b0b98
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion server/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:\n ${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:\n ${query}`)
benchmark = true
}

this.sequelize = new Sequelize({
dialect: 'sqlite',
storage: this.dbPath,
logging: false,
logging: logging,
benchmark: benchmark,
transactionType: 'IMMEDIATE'
})

Expand Down

0 comments on commit 97b0b98

Please sign in to comment.