2020-11-26 18:34:15 +01:00
|
|
|
const PouchDB = require("pouchdb")
|
2020-11-26 18:03:18 +01:00
|
|
|
|
2020-11-26 18:34:15 +01:00
|
|
|
const COUCHDB_OPTIONS = {
|
|
|
|
url: {
|
|
|
|
type: "string",
|
|
|
|
required: true,
|
|
|
|
default: "localhost",
|
|
|
|
},
|
|
|
|
database: {
|
|
|
|
type: "string",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
view: {
|
|
|
|
type: "string",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
}
|
2020-11-26 18:03:18 +01:00
|
|
|
|
2020-11-26 18:34:15 +01:00
|
|
|
class CouchDBIntegration {
|
|
|
|
constructor(config) {
|
|
|
|
this.config = config
|
|
|
|
this.client = new PouchDB(`${config.url}/${config.database}`)
|
|
|
|
}
|
2020-11-26 18:03:18 +01:00
|
|
|
|
2020-11-26 18:34:15 +01:00
|
|
|
async query() {
|
|
|
|
try {
|
|
|
|
const result = await this.client.allDocs({
|
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
return result.rows.map(row => row.doc)
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error querying couchDB", err)
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 18:03:18 +01:00
|
|
|
|
2020-11-26 18:34:15 +01:00
|
|
|
module.exports = {
|
|
|
|
schema: COUCHDB_OPTIONS,
|
|
|
|
integration: CouchDBIntegration,
|
|
|
|
}
|