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