2021-01-14 18:01:31 +01:00
|
|
|
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/"
|
2021-01-14 18:01:31 +01:00
|
|
|
|
2021-04-15 18:36:58 +02:00
|
|
|
let POUCH_DB_DEFAULTS = {
|
2021-01-14 18:01:31 +01:00
|
|
|
prefix: COUCH_DB_URL,
|
2021-08-17 17:48:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2021-08-17 17:48:02 +02:00
|
|
|
}
|
2021-04-15 18:36:58 +02:00
|
|
|
}
|
2021-01-14 18:01:31 +01:00
|
|
|
|
2021-04-15 17:25:48 +02:00
|
|
|
if (env.isTest()) {
|
|
|
|
PouchDB.plugin(require("pouchdb-adapter-memory"))
|
|
|
|
POUCH_DB_DEFAULTS = {
|
|
|
|
prefix: undefined,
|
|
|
|
adapter: "memory",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 18:36:58 +02:00
|
|
|
const Pouch = PouchDB.defaults(POUCH_DB_DEFAULTS)
|
|
|
|
|
2021-08-06 17:38:07 +02:00
|
|
|
// have to still have pouch alldbs for testing
|
2021-01-14 18:01:31 +01:00
|
|
|
allDbs(Pouch)
|
|
|
|
|
2021-01-14 18:02:05 +01:00
|
|
|
module.exports = Pouch
|