2022-02-08 21:22:42 +00:00
|
|
|
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') },
|
2022-02-08 22:19:53 +00:00
|
|
|
sessions: () => { return mdb.collection('u__sessions') },
|
2022-02-08 21:22:42 +00:00
|
|
|
},
|
|
|
|
}
|