use dynamic input in query
This commit is contained in:
parent
102b7ce61f
commit
b76d42bcde
|
@ -5,7 +5,7 @@
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
const BYTES_IN_MB = 1000000
|
const BYTES_IN_MB = 1000000
|
||||||
const FILE_SIZE_LIMIT = BYTES_IN_MB * 1
|
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
|
||||||
|
|
||||||
export let files = []
|
export let files = []
|
||||||
export let dataImport = {
|
export let dataImport = {
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
<script>
|
||||||
|
import { Select, Label, Spacer } from "@budibase/bbui"
|
||||||
|
import { store, backendUiStore, currentAsset } from "builderStore"
|
||||||
|
import fetchBindableProperties from "builderStore/fetchBindableProperties"
|
||||||
|
import ParameterBuilder from "../../../integration/QueryParameterBuilder.svelte"
|
||||||
|
|
||||||
|
export let parameters
|
||||||
|
|
||||||
|
let components = []
|
||||||
|
|
||||||
|
$: components = componentList($currentAsset)
|
||||||
|
|
||||||
|
// traverse the layout or screen tree
|
||||||
|
// and build an array of all available components
|
||||||
|
function componentList(asset) {
|
||||||
|
const components = []
|
||||||
|
|
||||||
|
function traverse(node) {
|
||||||
|
if (node._component) components.push(node)
|
||||||
|
|
||||||
|
if (node._children) node._children.forEach(traverse)
|
||||||
|
|
||||||
|
if (node.props) traverse(node.props)
|
||||||
|
}
|
||||||
|
|
||||||
|
traverse(asset.props)
|
||||||
|
|
||||||
|
return components
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="root">
|
||||||
|
<Label size="m" color="dark">Component</Label>
|
||||||
|
<Select thin secondary bind:value={parameters.componentId}>
|
||||||
|
<option value="" />
|
||||||
|
{#each components as component}
|
||||||
|
<option value={component._id}>{component._instanceName}</option>
|
||||||
|
{/each}
|
||||||
|
</Select>
|
||||||
|
</div>
|
|
@ -1,9 +1,11 @@
|
||||||
|
import { get } from "svelte/store"
|
||||||
import { fetchTableData } from "./tables"
|
import { fetchTableData } from "./tables"
|
||||||
import { fetchViewData } from "./views"
|
import { fetchViewData } from "./views"
|
||||||
import { fetchRelationshipData } from "./relationships"
|
import { fetchRelationshipData } from "./relationships"
|
||||||
import { executeQuery } from "./queries"
|
import { executeQuery } from "./queries"
|
||||||
import { enrichRows } from "./rows"
|
import { enrichRows } from "./rows"
|
||||||
import { enrichDataBindings } from "../utils/enrichDataBinding"
|
import { enrichDataBindings } from "../utils/enrichDataBinding"
|
||||||
|
import { bindingStore } from "../store/binding"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches all rows for a particular Budibase data source.
|
* Fetches all rows for a particular Budibase data source.
|
||||||
|
@ -21,12 +23,13 @@ export const fetchDatasource = async (datasource, dataContext) => {
|
||||||
} else if (type === "view") {
|
} else if (type === "view") {
|
||||||
rows = await fetchViewData(datasource)
|
rows = await fetchViewData(datasource)
|
||||||
} else if (type === "query") {
|
} else if (type === "query") {
|
||||||
console.log("Query Datasource", datasource)
|
const bindings = get(bindingStore)
|
||||||
console.log("Data Context", dataContext)
|
const fullContext = {
|
||||||
// TODO: You left here
|
...bindings,
|
||||||
const parameters = enrichDataBindings(datasource.queryParams, dataContext)
|
...dataContext,
|
||||||
console.log("PARSED PARAMS", parameters)
|
}
|
||||||
return await executeQuery({ _id: datasource._id, parameters })
|
const parameters = enrichDataBindings(datasource.queryParams, fullContext)
|
||||||
|
return await executeQuery({ queryId: datasource._id, parameters })
|
||||||
} else if (type === "link") {
|
} else if (type === "link") {
|
||||||
const row = dataContext[datasource.providerId]
|
const row = dataContext[datasource.providerId]
|
||||||
rows = await fetchRelationshipData({
|
rows = await fetchRelationshipData({
|
||||||
|
|
|
@ -10,5 +10,5 @@ export const executeQuery = async ({ queryId, parameters }) => {
|
||||||
parameters,
|
parameters,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return response.rows
|
return response
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ const { exportTemplateFromApp } = require("../src/utilities/templates")
|
||||||
const yargs = require("yargs")
|
const yargs = require("yargs")
|
||||||
|
|
||||||
// Script to export a chosen budibase app into a package
|
// Script to export a chosen budibase app into a package
|
||||||
// Usage: ./scripts/exportAppTemplate.js export --name=Funky --appId=someInstanceId --appId=appId
|
// Usage: ./scripts/exportAppTemplate.js export --name=Funky --appId=appId
|
||||||
|
|
||||||
yargs
|
yargs
|
||||||
.command(
|
.command(
|
||||||
|
|
|
@ -28,7 +28,7 @@ const SCHEMA = {
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
editor: {
|
query: {
|
||||||
sql: {
|
sql: {
|
||||||
type: "sql",
|
type: "sql",
|
||||||
},
|
},
|
||||||
|
@ -42,53 +42,6 @@ const SCHEMA = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const DATASOURCE_CONFIG = {
|
|
||||||
host: {
|
|
||||||
type: "string",
|
|
||||||
default: "localhost",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
port: {
|
|
||||||
type: "number",
|
|
||||||
required: true,
|
|
||||||
default: 5432,
|
|
||||||
},
|
|
||||||
database: {
|
|
||||||
type: "string",
|
|
||||||
default: "postgres",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
username: {
|
|
||||||
type: "string",
|
|
||||||
default: "root",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
password: {
|
|
||||||
type: "password",
|
|
||||||
default: "root",
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const QUERY_CONFIG = {
|
|
||||||
sql: {
|
|
||||||
type: "sql",
|
|
||||||
},
|
|
||||||
gui: {
|
|
||||||
type: "config",
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
type: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "",
|
|
||||||
type: "",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
class PostgresIntegration {
|
class PostgresIntegration {
|
||||||
constructor(config, query) {
|
constructor(config, query) {
|
||||||
this.config = config
|
this.config = config
|
||||||
|
@ -113,9 +66,6 @@ class PostgresIntegration {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
schema: {
|
schema: SCHEMA,
|
||||||
datasource: DATASOURCE_CONFIG,
|
|
||||||
query: QUERY_CONFIG,
|
|
||||||
},
|
|
||||||
integration: PostgresIntegration,
|
integration: PostgresIntegration,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
const { styleable, setBindableValue } = getContext("sdk")
|
const { styleable, setBindableValue } = getContext("sdk")
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
|
||||||
// Keep bindable value up to date
|
|
||||||
let value
|
let value
|
||||||
$: setBindableValue(value, $component.id)
|
|
||||||
|
function onBlur() {
|
||||||
|
setBindableValue(value, $component.id)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<input bind:value on:change={onchange} use:styleable={$component.styles} />
|
<input bind:value on:blur={onBlur} use:styleable={$component.styles} />
|
||||||
|
|
|
@ -57,9 +57,9 @@
|
||||||
pagination,
|
pagination,
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
async function fetchData() {
|
||||||
if (!isEmpty(datasource)) {
|
|
||||||
data = await API.fetchDatasource(datasource, $dataContext)
|
data = await API.fetchDatasource(datasource, $dataContext)
|
||||||
|
|
||||||
let schema
|
let schema
|
||||||
|
|
||||||
// Get schema for datasource
|
// Get schema for datasource
|
||||||
|
@ -114,6 +114,11 @@
|
||||||
|
|
||||||
dataLoaded = true
|
dataLoaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: datasource && fetchData()
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (!isEmpty(datasource)) fetchData()
|
||||||
})
|
})
|
||||||
|
|
||||||
const shouldHideField = name => {
|
const shouldHideField = name => {
|
||||||
|
@ -150,9 +155,7 @@
|
||||||
{#if selectedRows.length > 0}
|
{#if selectedRows.length > 0}
|
||||||
<DeleteButton text small on:click={modal.show()}>
|
<DeleteButton text small on:click={modal.show()}>
|
||||||
<Icon name="addrow" />
|
<Icon name="addrow" />
|
||||||
Delete
|
Delete {selectedRows.length} row(s)
|
||||||
{selectedRows.length}
|
|
||||||
row(s)
|
|
||||||
</DeleteButton>
|
</DeleteButton>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue