39 lines
951 B
JavaScript
39 lines
951 B
JavaScript
import Database from 'better-sqlite3'
|
|
import initLog from '../utils/log.js'
|
|
|
|
/**
|
|
* @type {Database.Database}
|
|
*/
|
|
export let sqlite = undefined
|
|
|
|
/**
|
|
* @type {Database.Database}
|
|
*/
|
|
export let skinDB = undefined
|
|
|
|
const log = initLog("Database")
|
|
|
|
/**
|
|
* This initalizes the ddnet.sqlite and skindata.sqlite DB...
|
|
* @module db/dbInit
|
|
*/
|
|
export function dbInit() {
|
|
log("Starting up databases...")
|
|
|
|
/* load in db using better-sqlite3 */
|
|
sqlite = new Database(process.env.DATA_DIR ? `${process.env.DATA_DIR}/ddnet.sqlite` : 'data/ddnet.sqlite', { });
|
|
skinDB = new Database(process.env.DATA_DIR ? `${process.env.DATA_DIR}/skindata.sqlite` : 'data/skindata.sqlite', { });
|
|
|
|
/* WAL mode */
|
|
sqlite.pragma('journal_mode = WAL');
|
|
|
|
/* Unsafe mode */
|
|
sqlite.unsafeMode()
|
|
|
|
/* Load external extensions */
|
|
sqlite.loadExtension('./math-func.so')
|
|
|
|
log("Loaded in 'ddnet.sqlite'!")
|
|
log("Loaded in 'skindata.sqlite'!")
|
|
}
|