1
0
Fork 0
mirror of synced 2024-06-15 08:54:53 +12:00

read all columns for schema rather than just the first

This commit is contained in:
Martin McKeaveney 2021-02-22 17:41:02 +00:00
parent bcdcee11b1
commit 692c5a9b3e
5 changed files with 24 additions and 9 deletions

View file

@ -3,13 +3,14 @@
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
export let integration
export let schema
let unsaved = false
</script>
<form>
{#each Object.keys(integration) as configKey}
{#if typeof integration[configKey] === 'object'}
{#each Object.keys(schema) as configKey}
{#if typeof schema[configKey].type === 'object'}
<Label small>{configKey}</Label>
<Spacer small />
<KeyValueBuilder bind:object={integration[configKey]} on:change />
@ -18,7 +19,7 @@
<Label small>{configKey}</Label>
<Input
outline
type={integration[configKey].type}
type={schema[configKey].type}
on:change
bind:value={integration[configKey]} />
</div>

View file

@ -92,7 +92,7 @@
if (response.status !== 200) throw new Error(json.message)
data = json || []
data = json.rows || []
if (data.length === 0) {
notifier.info(
@ -103,9 +103,9 @@
notifier.success("Query executed successfully.")
// Assume all the fields are strings and create a basic schema
// from the first record returned by the query
fields = Object.keys(json[0]).map(field => ({
// Assume all the fields are strings and create a basic schema from the
// unique fields returned by the server
fields = json.schemaFields.map(field => ({
name: field,
type: "STRING",
}))

View file

@ -13,6 +13,11 @@
)
$: integration = datasource && $backendUiStore.integrations[datasource.source]
$: console.log({
datasource,
integration,
})
async function saveDatasource() {
// Create datasource
await backendUiStore.actions.datasources.save(datasource)
@ -74,6 +79,7 @@
<Spacer extraLarge />
<IntegrationConfigForm
schema={integration.datasource}
integration={datasource.config}
on:change={setUnsaved} />
<Spacer extraLarge />

View file

@ -115,9 +115,17 @@ exports.preview = async function(ctx) {
const enrichedQuery = await enrichQueryFields(fields, parameters)
ctx.body = formatResponse(
const rows = formatResponse(
await new Integration(datasource.config)[queryVerb](enrichedQuery)
)
// get all the potential fields in the schema
const keys = rows.flatMap(Object.keys)
ctx.body = {
rows,
schemaFields: [...new Set(keys)],
}
}
exports.execute = async function(ctx) {

View file

@ -8,7 +8,7 @@ const SCHEMA = {
friendlyName: "Airtable",
datasource: {
apiKey: {
type: FIELD_TYPES.STRING,
type: FIELD_TYPES.PASSWORD,
default: "enter api key",
required: true,
},