budibase/packages/backend-core/src/db/index.js

37 lines
656 B
JavaScript
Raw Normal View History

const pouch = require("./pouch")
let PouchDB
let initialised = false
const put =
dbPut =>
async (doc, options = {}) => {
const response = await dbPut(doc, options)
// TODO: add created / updated
return response
}
const checkInitialised = () => {
if (!initialised) {
throw new Error("init has not been called")
}
}
exports.init = opts => {
PouchDB = pouch.getPouch(opts)
initialised = true
}
2021-04-15 17:57:01 +02:00
exports.getDB = (dbName, opts) => {
checkInitialised()
const db = new PouchDB(dbName, opts)
const dbPut = db.put
db.put = put(dbPut)
return db
}
2021-05-14 17:31:07 +02:00
exports.allDbs = () => {
checkInitialised()
return PouchDB.allDbs()
2021-05-14 17:31:07 +02:00
}