2022-03-29 17:03:44 +02:00
|
|
|
const pouch = require("./pouch")
|
2021-04-20 18:17:44 +02:00
|
|
|
|
2022-03-29 17:03:44 +02:00
|
|
|
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:45:21 +02:00
|
|
|
}
|
2021-04-15 17:57:01 +02:00
|
|
|
|
2022-03-29 17:03:44 +02:00
|
|
|
exports.getDB = (dbName, opts) => {
|
|
|
|
checkInitialised()
|
|
|
|
const db = new PouchDB(dbName, opts)
|
|
|
|
const dbPut = db.put
|
|
|
|
db.put = put(dbPut)
|
|
|
|
return db
|
2021-04-20 18:17:44 +02:00
|
|
|
}
|
2021-05-14 17:31:07 +02:00
|
|
|
|
2022-03-29 17:03:44 +02:00
|
|
|
exports.allDbs = () => {
|
|
|
|
checkInitialised()
|
|
|
|
return PouchDB.allDbs()
|
2021-05-14 17:31:07 +02:00
|
|
|
}
|