2021-10-30 20:26:37 +02:00
|
|
|
import Database from 'better-sqlite3'
|
2021-11-01 15:09:03 +01:00
|
|
|
import initLog from '../utils/log.js'
|
2021-10-30 20:26:37 +02:00
|
|
|
|
2021-11-04 20:06:51 +01:00
|
|
|
/**
|
|
|
|
* @type {Database.Database}
|
|
|
|
*/
|
2021-10-30 20:26:37 +02:00
|
|
|
export let sqlite = undefined
|
2021-11-04 20:06:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Database.Database}
|
|
|
|
*/
|
2021-10-30 20:26:37 +02:00
|
|
|
export let skinDB = undefined
|
|
|
|
|
2021-11-01 18:12:46 +01:00
|
|
|
const log = initLog("Database")
|
2021-11-01 15:09:03 +01:00
|
|
|
|
2021-10-30 20:26:37 +02:00
|
|
|
/**
|
|
|
|
* This initalizes the ddnet.sqlite and skindata.sqlite DB...
|
|
|
|
* @module db/dbInit
|
|
|
|
*/
|
|
|
|
export function dbInit() {
|
2021-11-01 18:12:46 +01:00
|
|
|
log("Starting up databases...")
|
2021-10-30 20:26:37 +02:00
|
|
|
|
|
|
|
/* load in db using better-sqlite3 */
|
2021-11-04 23:12:51 +01:00
|
|
|
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', { });
|
2021-10-30 20:26:37 +02:00
|
|
|
|
|
|
|
/* WAL mode */
|
|
|
|
sqlite.pragma('journal_mode = WAL');
|
|
|
|
|
|
|
|
/* Unsafe mode */
|
|
|
|
sqlite.unsafeMode()
|
|
|
|
|
2021-11-04 15:40:12 +01:00
|
|
|
/* Load external extensions */
|
|
|
|
sqlite.loadExtension('./math-func.so')
|
|
|
|
|
2021-11-01 18:12:46 +01:00
|
|
|
log("Loaded in 'ddnet.sqlite'!")
|
|
|
|
log("Loaded in 'skindata.sqlite'!")
|
2021-10-30 20:26:37 +02:00
|
|
|
}
|