2021-10-13 16:40:18 +02:00
|
|
|
import initLog from '../utils/log.js'
|
2021-09-29 20:29:06 +02:00
|
|
|
import mongoose from 'mongoose'
|
|
|
|
import sqlite3 from 'sqlite3'
|
|
|
|
import { open } from 'sqlite'
|
|
|
|
|
|
|
|
const log = initLog("database")
|
|
|
|
|
2021-10-16 19:58:00 +02:00
|
|
|
export let sqlite = undefined
|
2021-09-29 20:29:06 +02:00
|
|
|
|
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
|
|
|
|
}
|
2021-10-16 19:58:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
log("Connected to mongodb!")
|
2021-09-29 20:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default init
|