ddstats-server/libs/database/init.js

33 lines
713 B
JavaScript
Raw Normal View History

2021-09-29 20:29:06 +02:00
import initLog from '../utills/log.js'
import mongoose from 'mongoose'
import sqlite3 from 'sqlite3'
import { open } from 'sqlite'
const log = initLog("database")
export let sqlite = undefined
2021-10-06 20:36:20 +02:00
/**
* This initializes both the sqlite db and mongodb.
* @module libs/database/init
*/
2021-09-29 20:29:06 +02:00
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
}
).then(() => log("Connected to mongodb!"))
}
export default init