ddstats-server/libs/database/init.js

35 lines
705 B
JavaScript

import initLog from '../utils/log.js'
import mongoose from 'mongoose'
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
const log = initLog("database")
export let sqlite = undefined
/**
* This initializes both the sqlite db and mongodb.
* @module libs/database/init
*/
async function init() {
log("Starting up databases...")
sqlite = await open({
filename: 'ddnet.sqlite',
driver: sqlite3.cached.Database
})
log("Loaded in 'ddnet.sqlite'!")
await mongoose.connect(
process.env.MONGO_URI,
{
useNewUrlParser: true,
useUnifiedTopology: true
}
)
log("Connected to mongodb!")
}
export default init