2020-04-24 10:54:20 +02:00
|
|
|
const PouchDB = require("pouchdb")
|
2020-04-25 09:35:34 +02:00
|
|
|
const allDbs = require("pouchdb-all-dbs")
|
2020-05-11 16:42:42 +02:00
|
|
|
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
2020-05-14 16:12:30 +02:00
|
|
|
const env = require("../environment")
|
2020-04-07 16:12:08 +02:00
|
|
|
|
2020-05-18 07:40:29 +02:00
|
|
|
const COUCH_DB_URL = env.COUCH_DB_URL || `leveldb://${budibaseAppsDir().replace(/\\/g, "/")}/.data/`
|
2020-05-14 16:12:30 +02:00
|
|
|
const isInMemory = env.NODE_ENV === "jest"
|
|
|
|
|
|
|
|
if (isInMemory) PouchDB.plugin(require("pouchdb-adapter-memory"))
|
2020-04-28 15:39:35 +02:00
|
|
|
|
|
|
|
const Pouch = PouchDB.defaults({
|
2020-05-14 16:12:30 +02:00
|
|
|
prefix: isInMemory ? undefined : COUCH_DB_URL,
|
|
|
|
adapter: isInMemory ? "memory" : undefined,
|
2020-05-07 11:53:34 +02:00
|
|
|
})
|
2020-04-28 15:39:35 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
allDbs(Pouch)
|
2020-04-28 15:39:35 +02:00
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
module.exports = Pouch
|