budibase/packages/worker/src/db/index.js

33 lines
741 B
JavaScript
Raw Normal View History

const PouchDB = require("pouchdb")
const allDbs = require("pouchdb-all-dbs")
const env = require("../environment")
// level option is purely for testing (development)
2021-03-22 17:18:29 +01:00
const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/"
let POUCH_DB_DEFAULTS = {
prefix: COUCH_DB_URL,
}
if (env.COUCH_DB_USERNAME && env.COUCH_DB_PASSWORD) {
POUCH_DB_DEFAULTS.auth = {
2021-08-17 15:11:03 +02:00
username: env.COUCH_DB_USERNAME,
password: env.COUCH_DB_PASSWORD,
}
}
if (env.isTest()) {
PouchDB.plugin(require("pouchdb-adapter-memory"))
POUCH_DB_DEFAULTS = {
prefix: undefined,
adapter: "memory",
}
}
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
// have to still have pouch alldbs for testing
allDbs(Pouch)
2021-01-14 18:02:05 +01:00
module.exports = Pouch