From c12b59e3048897b84fd49023c5cfa0e134f4ef7f Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 26 Nov 2020 17:34:15 +0000 Subject: [PATCH] CouchDB integration E2E --- .../modals/EditIntegrationConfig.svelte | 10 ++- .../TableNavigator/TableNavigator.svelte | 3 +- packages/server/src/integrations/couchdb.js | 76 +++++++++---------- .../server/src/integrations/elasticsearch.js | 3 + 4 files changed, 48 insertions(+), 44 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/EditIntegrationConfig.svelte b/packages/builder/src/components/backend/DataTable/modals/EditIntegrationConfig.svelte index 48bb22320c..4789b6f8f0 100644 --- a/packages/builder/src/components/backend/DataTable/modals/EditIntegrationConfig.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/EditIntegrationConfig.svelte @@ -49,7 +49,9 @@ - deleteField(idx)} /> + deleteField(idx)} /> {/each} @@ -72,7 +74,7 @@ .field { display: grid; grid-gap: 10px; - grid-template-columns: 1fr 1fr; + grid-template-columns: 1fr 1fr 50px; margin-bottom: var(--spacing-m); } @@ -91,7 +93,7 @@ margin-bottom: var(--spacing-s); } - form > * { - margin-bottom: var(--spacing-s); + .delete { + align-self: center; } diff --git a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte index 5a57fe6a4a..eb5cfffa6d 100644 --- a/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte +++ b/packages/builder/src/components/backend/TableNavigator/TableNavigator.svelte @@ -9,6 +9,7 @@ import NavItem from "components/common/NavItem.svelte" let modal + $: selectedView = $backendUiStore.selectedView && $backendUiStore.selectedView.name @@ -42,7 +43,7 @@ {#each $backendUiStore.tables as table, idx} 0} - icon="ri-table-line" + icon={table.integration ? 'ri-database-2-line' : 'ri-table-line'} text={table.name} selected={selectedView === `all_${table._id}`} on:click={() => selectTable(table)}> diff --git a/packages/server/src/integrations/couchdb.js b/packages/server/src/integrations/couchdb.js index e44cf9e34c..ef5a1ebe9b 100644 --- a/packages/server/src/integrations/couchdb.js +++ b/packages/server/src/integrations/couchdb.js @@ -1,43 +1,41 @@ -// const PouchDB = require("pouchdb") +const PouchDB = require("pouchdb") -// const COUCHDB_OPTIONS = { -// url: { -// type: "string", -// required: true, -// default: "localhost", -// }, -// database: { -// type: "string", -// required: true, -// }, -// // query: { -// // type: "query", -// // required: true, -// // }, -// } +const COUCHDB_OPTIONS = { + url: { + type: "string", + required: true, + default: "localhost", + }, + database: { + type: "string", + required: true, + }, + view: { + type: "string", + required: true, + }, +} -// class ElasticSearchIntegration { -// constructor(config) { -// this.config = config -// this.client = new Client({ node: config.url }) -// } - -// async query() { -// try { -// const result = await this.client.search({ -// index: this.config.index, -// body: JSON.parse(this.config.query), -// }) -// return result -// } finally { -// await this.client.close() -// } -// } -// } - -// module.exports = { -// schema: ELASTICSEARCH_OPTIONS, -// integration: ElasticSearchIntegration, -// } +class CouchDBIntegration { + constructor(config) { + this.config = config + this.client = new PouchDB(`${config.url}/${config.database}`) + } + 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 + } + } +} +module.exports = { + schema: COUCHDB_OPTIONS, + integration: CouchDBIntegration, +} diff --git a/packages/server/src/integrations/elasticsearch.js b/packages/server/src/integrations/elasticsearch.js index d030bae9c8..d5074bb26f 100644 --- a/packages/server/src/integrations/elasticsearch.js +++ b/packages/server/src/integrations/elasticsearch.js @@ -29,6 +29,9 @@ class ElasticSearchIntegration { body: JSON.parse(this.config.query), }) return result.body.hits.hits.map(({ _source }) => _source) + } catch (err) { + console.error("Error querying elasticsearch", err) + throw err } finally { await this.client.close() }