Fixing issue with switching between datasources and making sure old client apps can still use the deprecated API.
This commit is contained in:
parent
858ef084ad
commit
a9437302b7
|
@ -21,11 +21,11 @@
|
|||
import { cloneDeep } from "lodash/fp"
|
||||
|
||||
import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte"
|
||||
import { onMount } from "svelte"
|
||||
let importQueriesModal
|
||||
|
||||
let changed
|
||||
let datasource
|
||||
let integration, baseDatasource, datasource
|
||||
let queryList
|
||||
const querySchema = {
|
||||
name: {},
|
||||
queryVerb: { displayName: "Method" },
|
||||
|
@ -34,11 +34,12 @@
|
|||
$: baseDatasource = $datasources.list.find(
|
||||
ds => ds._id === $datasources.selected
|
||||
)
|
||||
$: integration = datasource && $integrations[datasource.source]
|
||||
|
||||
$: queryList = $queries.list.filter(
|
||||
query => query.datasourceId === datasource?._id
|
||||
)
|
||||
$: hasChanged(baseDatasource, datasource)
|
||||
$: updateDatasource(baseDatasource)
|
||||
|
||||
function hasChanged(base, ds) {
|
||||
if (base && ds) {
|
||||
|
@ -66,9 +67,12 @@
|
|||
$goto(`./${query._id}`)
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
datasource = cloneDeep(baseDatasource)
|
||||
})
|
||||
function updateDatasource(base) {
|
||||
if (base) {
|
||||
datasource = cloneDeep(base)
|
||||
integration = $integrations[datasource.source]
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:this={importQueriesModal}>
|
||||
|
|
|
@ -11,7 +11,7 @@ export const executeQuery = async ({ queryId, parameters }) => {
|
|||
return
|
||||
}
|
||||
const res = await API.post({
|
||||
url: `/api/queries/${queryId}`,
|
||||
url: `/api/v2/queries/${queryId}`,
|
||||
body: {
|
||||
parameters,
|
||||
},
|
||||
|
|
|
@ -169,7 +169,7 @@ exports.preview = async function (ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
exports.execute = async function (ctx) {
|
||||
async function execute(ctx, opts = { rowsOnly: false }) {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
|
||||
const query = await db.get(ctx.params.queryId)
|
||||
|
@ -188,12 +188,24 @@ exports.execute = async function (ctx) {
|
|||
query: enrichedQuery,
|
||||
transformer: query.transformer,
|
||||
})
|
||||
ctx.body = { data: rows, ...extra }
|
||||
if (opts && opts.rowsOnly) {
|
||||
ctx.body = rows
|
||||
} else {
|
||||
ctx.body = { data: rows, ...extra }
|
||||
}
|
||||
} catch (err) {
|
||||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
||||
exports.executeV1 = async function (ctx) {
|
||||
return execute(ctx, { rowsOnly: true })
|
||||
}
|
||||
|
||||
exports.executeV2 = async function (ctx) {
|
||||
return execute(ctx, { rowsOnly: false })
|
||||
}
|
||||
|
||||
exports.destroy = async function (ctx) {
|
||||
const db = new CouchDB(ctx.appId)
|
||||
await db.remove(ctx.params.queryId, ctx.params.revId)
|
||||
|
|
|
@ -41,11 +41,18 @@ router
|
|||
authorized(PermissionTypes.QUERY, PermissionLevels.READ),
|
||||
queryController.find
|
||||
)
|
||||
// DEPRECATED - use new query endpoint for future work
|
||||
.post(
|
||||
"/api/queries/:queryId",
|
||||
paramResource("queryId"),
|
||||
authorized(PermissionTypes.QUERY, PermissionLevels.WRITE),
|
||||
queryController.execute
|
||||
queryController.executeV1
|
||||
)
|
||||
.post(
|
||||
"/api/v2/queries/:queryId",
|
||||
paramResource("queryId"),
|
||||
authorized(PermissionTypes.QUERY, PermissionLevels.WRITE),
|
||||
queryController.executeV2
|
||||
)
|
||||
.delete(
|
||||
"/api/queries/:queryId/:revId",
|
||||
|
|
Loading…
Reference in New Issue