Skip to content

Commit 23067e1

Browse files
committed
Allows setting of some pragma values through environment variables
1 parent e096da1 commit 23067e1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

server/Database.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,28 @@ class Database {
226226

227227
try {
228228
await this.sequelize.authenticate()
229+
230+
// Set SQLite pragmas from environment variables
231+
const allowedPragmas = [
232+
{ name: 'mmap_size', env: 'SQLITE_MMAP_SIZE' },
233+
{ name: 'cache_size', env: 'SQLITE_CACHE_SIZE' },
234+
{ name: 'temp_store', env: 'SQLITE_TEMP_STORE' }
235+
]
236+
237+
for (const pragma of allowedPragmas) {
238+
const value = process.env[pragma.env]
239+
if (value !== undefined) {
240+
try {
241+
Logger.info(`[Database] Running "PRAGMA ${pragma.name} = ${value}"`)
242+
await this.sequelize.query(`PRAGMA ${pragma.name} = ${value}`)
243+
const [result] = await this.sequelize.query(`PRAGMA ${pragma.name}`)
244+
Logger.debug(`[Database] "PRAGMA ${pragma.name}" query result:`, result)
245+
} catch (error) {
246+
Logger.error(`[Database] Failed to set SQLite pragma ${pragma.name}`, error)
247+
}
248+
}
249+
}
250+
229251
if (process.env.NUSQLITE3_PATH) {
230252
await this.loadExtension(process.env.NUSQLITE3_PATH)
231253
Logger.info(`[Database] Db supports unaccent and unicode foldings`)

0 commit comments

Comments
 (0)