fedilove/api/src/db.js

25 lines
554 B
JavaScript
Raw Normal View History

const { MongoClient } = require('mongodb')
global.mconn = null
global.mdb = null
module.exports = {
conn: () => {
if (mconn !== null)
return mconn
const dbhost = process.env.DB_HOST || 'db'
mconn = new MongoClient('mongodb://'+dbhost+':27017', {
useUnifiedTopology: true,
useNewUrlParser: true
})
return mconn
},
get: () => {
mdb = mconn.db(process.env.DB_NAME || 'activitypub')
return mdb
},
table: {
users: () => { return mdb.collection('u__users') },
sessions: () => { return mdb.collection('u__sessions') },
},
}