Singleton connection
I think the suggested way to access the db connection is by using .then
and set it to the app
(in case of express). Is it possible to have a way to get a singleton connection? I think it can be used if you want to abstract database operations in their own methods like:
import db from './db'
export createTask = async (task, db) => {
return await db.saveDoc('tasks', task)
}
then I can use this on request handler of the app
router.post('/tasks', async ctx => {
const task = await createTask( ctx.request.body)
ctx.status = 201
ctx.body = task
})