CouchDB integration E2E

This commit is contained in:
Martin McKeaveney 2020-11-26 17:34:15 +00:00
parent 4d3e134145
commit c12b59e304
4 changed files with 48 additions and 44 deletions

View File

@ -49,7 +49,9 @@
<option value={'BOOLEAN'}>Boolean</option> <option value={'BOOLEAN'}>Boolean</option>
<option value={'DATETIME'}>Datetime</option> <option value={'DATETIME'}>Datetime</option>
</Select> </Select>
<i class="ri-close-circle-line" on:click={() => deleteField(idx)} /> <i
class="ri-close-circle-line delete"
on:click={() => deleteField(idx)} />
</div> </div>
{/each} {/each}
<Button thin secondary on:click={newField}>Add Field</Button> <Button thin secondary on:click={newField}>Add Field</Button>
@ -72,7 +74,7 @@
.field { .field {
display: grid; display: grid;
grid-gap: 10px; grid-gap: 10px;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr 50px;
margin-bottom: var(--spacing-m); margin-bottom: var(--spacing-m);
} }
@ -91,7 +93,7 @@
margin-bottom: var(--spacing-s); margin-bottom: var(--spacing-s);
} }
form > * { .delete {
margin-bottom: var(--spacing-s); align-self: center;
} }
</style> </style>

View File

@ -9,6 +9,7 @@
import NavItem from "components/common/NavItem.svelte" import NavItem from "components/common/NavItem.svelte"
let modal let modal
$: selectedView = $: selectedView =
$backendUiStore.selectedView && $backendUiStore.selectedView.name $backendUiStore.selectedView && $backendUiStore.selectedView.name
@ -42,7 +43,7 @@
{#each $backendUiStore.tables as table, idx} {#each $backendUiStore.tables as table, idx}
<NavItem <NavItem
border={idx > 0} border={idx > 0}
icon="ri-table-line" icon={table.integration ? 'ri-database-2-line' : 'ri-table-line'}
text={table.name} text={table.name}
selected={selectedView === `all_${table._id}`} selected={selectedView === `all_${table._id}`}
on:click={() => selectTable(table)}> on:click={() => selectTable(table)}>

View File

@ -1,43 +1,41 @@
// const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
// const COUCHDB_OPTIONS = { const COUCHDB_OPTIONS = {
// url: { url: {
// type: "string", type: "string",
// required: true, required: true,
// default: "localhost", default: "localhost",
// }, },
// database: { database: {
// type: "string", type: "string",
// required: true, required: true,
// }, },
// // query: { view: {
// // type: "query", type: "string",
// // required: true, required: true,
// // }, },
// } }
// class ElasticSearchIntegration { class CouchDBIntegration {
// constructor(config) { constructor(config) {
// this.config = config this.config = config
// this.client = new Client({ node: config.url }) this.client = new PouchDB(`${config.url}/${config.database}`)
// } }
// 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,
// }
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,
}

View File

@ -29,6 +29,9 @@ class ElasticSearchIntegration {
body: JSON.parse(this.config.query), body: JSON.parse(this.config.query),
}) })
return result.body.hits.hits.map(({ _source }) => _source) return result.body.hits.hits.map(({ _source }) => _source)
} catch (err) {
console.error("Error querying elasticsearch", err)
throw err
} finally { } finally {
await this.client.close() await this.client.close()
} }