PR comments.
This commit is contained in:
parent
f62ffb38e2
commit
f857c36e09
|
@ -59,15 +59,11 @@ export function isExternalTable(table: Table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildExternalTableId(datasourceId: string, tableName: string) {
|
export function buildExternalTableId(datasourceId: string, tableName: string) {
|
||||||
// encode spaces
|
return `${datasourceId}${DOUBLE_SEPARATOR}${encodeURIComponent(tableName)}`
|
||||||
if (tableName.includes(" ")) {
|
|
||||||
tableName = encodeURIComponent(tableName)
|
|
||||||
}
|
|
||||||
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkTableId(tableId: string) {
|
export function encodeTableId(tableId: string) {
|
||||||
if (isExternalTableID(tableId) && tableId.includes(" ")) {
|
if (isExternalTableID(tableId)) {
|
||||||
return encodeURIComponent(tableId)
|
return encodeURIComponent(tableId)
|
||||||
} else {
|
} else {
|
||||||
return tableId
|
return tableId
|
||||||
|
|
|
@ -65,21 +65,19 @@ export function getSourceId(ctx: Ctx): { tableId: string; viewId?: string } {
|
||||||
const { sourceId } = ctx.params
|
const { sourceId } = ctx.params
|
||||||
if (docIds.isViewId(sourceId)) {
|
if (docIds.isViewId(sourceId)) {
|
||||||
return {
|
return {
|
||||||
tableId: sql.utils.checkTableId(
|
tableId: utils.extractViewInfoFromID(sourceId).tableId,
|
||||||
utils.extractViewInfoFromID(sourceId).tableId
|
|
||||||
),
|
|
||||||
viewId: sourceId,
|
viewId: sourceId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { tableId: sql.utils.checkTableId(ctx.params.sourceId) }
|
return { tableId: sql.utils.encodeTableId(ctx.params.sourceId) }
|
||||||
}
|
}
|
||||||
// now check for old way of specifying table ID
|
// now check for old way of specifying table ID
|
||||||
if (ctx.params?.tableId) {
|
if (ctx.params?.tableId) {
|
||||||
return { tableId: sql.utils.checkTableId(ctx.params.tableId) }
|
return { tableId: sql.utils.encodeTableId(ctx.params.tableId) }
|
||||||
}
|
}
|
||||||
// check body for a table ID
|
// check body for a table ID
|
||||||
if (ctx.request.body?.tableId) {
|
if (ctx.request.body?.tableId) {
|
||||||
return { tableId: sql.utils.checkTableId(ctx.request.body.tableId) }
|
return { tableId: sql.utils.encodeTableId(ctx.request.body.tableId) }
|
||||||
}
|
}
|
||||||
throw new Error("Unable to find table ID in request")
|
throw new Error("Unable to find table ID in request")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { context, db as dbCore, docIds, utils } from "@budibase/backend-core"
|
import {
|
||||||
|
context,
|
||||||
|
db as dbCore,
|
||||||
|
docIds,
|
||||||
|
utils,
|
||||||
|
sql,
|
||||||
|
} from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
DatabaseQueryOpts,
|
DatabaseQueryOpts,
|
||||||
Datasource,
|
Datasource,
|
||||||
|
@ -328,7 +334,7 @@ export function extractViewInfoFromID(viewId: string) {
|
||||||
const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`)
|
const regex = new RegExp(`^(?<tableId>.+)${SEPARATOR}([^${SEPARATOR}]+)$`)
|
||||||
const res = regex.exec(viewId)
|
const res = regex.exec(viewId)
|
||||||
return {
|
return {
|
||||||
tableId: res!.groups!["tableId"],
|
tableId: sql.utils.encodeTableId(res!.groups!["tableId"]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue