This commit is contained in:
furo 2021-11-04 20:31:16 +01:00
commit 355c0ab670
3 changed files with 11 additions and 5 deletions

View File

@ -21,7 +21,7 @@ const log = initLog("[ MAIN ]")
// Read the .env file // Read the .env file
dotenv.config() dotenv.config()
if (process.env.DOWNLOAD_FILES === "true") if (process.env.DOWNLOAD_FILES === "enabled")
await downloadEssentialData() await downloadEssentialData()
dbInit() dbInit()

View File

@ -10,8 +10,8 @@ const log = initLog("DB Generation")
* @module db/generateDB * @module db/generateDB
*/ */
export function generateDB() { export function generateDB() {
if (process.env.GENERATE_DB !== "true") if (process.env.GENERATE_DB !== "enabled")
return log("Won't generate the database since 'GENERATE_DB' is not set to \"true\" in '.env'!") return log("Won't generate the database since 'GENERATE_DB' is not set to \"enabled\" in '.env'!")
const exists = sqlite.prepare(`SELECT count(*) as a FROM sqlite_master WHERE type='table' AND name='points'`).get() const exists = sqlite.prepare(`SELECT count(*) as a FROM sqlite_master WHERE type='table' AND name='points'`).get()
if(exists.a === 1) if(exists.a === 1)

View File

@ -1,8 +1,14 @@
import Database from 'better-sqlite3' import Database from 'better-sqlite3'
import initLog from '../utils/log.js' import initLog from '../utils/log.js'
/* Export DB for use in other files */ /**
* @type {Database.Database}
*/
export let sqlite = undefined export let sqlite = undefined
/**
* @type {Database.Database}
*/
export let skinDB = undefined export let skinDB = undefined
const log = initLog("Database") const log = initLog("Database")
@ -15,7 +21,7 @@ export function dbInit() {
log("Starting up databases...") log("Starting up databases...")
/* load in db using better-sqlite3 */ /* load in db using better-sqlite3 */
sqlite = new Database(process.env.DDNET_SQLITE_PATH ?? 'data/ddnet.sqlite', { verbose: console.log }); sqlite = new Database(process.env.DDNET_SQLITE_PATH ?? 'data/ddnet.sqlite', { });
skinDB = new Database(process.env.DDNSS_SQLITE_PATH ?? 'data/skindata.sqlite', { }); skinDB = new Database(process.env.DDNSS_SQLITE_PATH ?? 'data/skindata.sqlite', { });
/* WAL mode */ /* WAL mode */