Fixing issue with switching between datasources and making sure old client apps can still use the deprecated API.

This commit is contained in:
mike12345567 2021-12-16 11:41:28 +00:00
parent 858ef084ad
commit a9437302b7
4 changed files with 33 additions and 10 deletions

View File

@ -21,11 +21,11 @@
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte" import ImportRestQueriesModal from "components/backend/DatasourceNavigator/modals/ImportRestQueriesModal.svelte"
import { onMount } from "svelte"
let importQueriesModal let importQueriesModal
let changed let changed
let datasource let integration, baseDatasource, datasource
let queryList
const querySchema = { const querySchema = {
name: {}, name: {},
queryVerb: { displayName: "Method" }, queryVerb: { displayName: "Method" },
@ -34,11 +34,12 @@
$: baseDatasource = $datasources.list.find( $: baseDatasource = $datasources.list.find(
ds => ds._id === $datasources.selected ds => ds._id === $datasources.selected
) )
$: integration = datasource && $integrations[datasource.source]
$: queryList = $queries.list.filter( $: queryList = $queries.list.filter(
query => query.datasourceId === datasource?._id query => query.datasourceId === datasource?._id
) )
$: hasChanged(baseDatasource, datasource) $: hasChanged(baseDatasource, datasource)
$: updateDatasource(baseDatasource)
function hasChanged(base, ds) { function hasChanged(base, ds) {
if (base && ds) { if (base && ds) {
@ -66,9 +67,12 @@
$goto(`./${query._id}`) $goto(`./${query._id}`)
} }
onMount(() => { function updateDatasource(base) {
datasource = cloneDeep(baseDatasource) if (base) {
}) datasource = cloneDeep(base)
integration = $integrations[datasource.source]
}
}
</script> </script>
<Modal bind:this={importQueriesModal}> <Modal bind:this={importQueriesModal}>

View File

@ -11,7 +11,7 @@ export const executeQuery = async ({ queryId, parameters }) => {
return return
} }
const res = await API.post({ const res = await API.post({
url: `/api/queries/${queryId}`, url: `/api/v2/queries/${queryId}`,
body: { body: {
parameters, parameters,
}, },

View File

@ -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 db = new CouchDB(ctx.appId)
const query = await db.get(ctx.params.queryId) const query = await db.get(ctx.params.queryId)
@ -188,12 +188,24 @@ exports.execute = async function (ctx) {
query: enrichedQuery, query: enrichedQuery,
transformer: query.transformer, transformer: query.transformer,
}) })
ctx.body = { data: rows, ...extra } if (opts && opts.rowsOnly) {
ctx.body = rows
} else {
ctx.body = { data: rows, ...extra }
}
} catch (err) { } catch (err) {
ctx.throw(400, 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) { exports.destroy = async function (ctx) {
const db = new CouchDB(ctx.appId) const db = new CouchDB(ctx.appId)
await db.remove(ctx.params.queryId, ctx.params.revId) await db.remove(ctx.params.queryId, ctx.params.revId)

View File

@ -41,11 +41,18 @@ router
authorized(PermissionTypes.QUERY, PermissionLevels.READ), authorized(PermissionTypes.QUERY, PermissionLevels.READ),
queryController.find queryController.find
) )
// DEPRECATED - use new query endpoint for future work
.post( .post(
"/api/queries/:queryId", "/api/queries/:queryId",
paramResource("queryId"), paramResource("queryId"),
authorized(PermissionTypes.QUERY, PermissionLevels.WRITE), authorized(PermissionTypes.QUERY, PermissionLevels.WRITE),
queryController.execute queryController.executeV1
)
.post(
"/api/v2/queries/:queryId",
paramResource("queryId"),
authorized(PermissionTypes.QUERY, PermissionLevels.WRITE),
queryController.executeV2
) )
.delete( .delete(
"/api/queries/:queryId/:revId", "/api/queries/:queryId/:revId",