1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

CouchDB integration E2E

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

View file

@ -49,7 +49,9 @@
<option value={'BOOLEAN'}>Boolean</option>
<option value={'DATETIME'}>Datetime</option>
</Select>
<i class="ri-close-circle-line" on:click={() => deleteField(idx)} />
<i
class="ri-close-circle-line delete"
on:click={() => deleteField(idx)} />
</div>
{/each}
<Button thin secondary on:click={newField}>Add Field</Button>
@ -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;
}
</style>

View file

@ -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}
<NavItem
border={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)}>

View file

@ -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,
}

View file

@ -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()
}