Addressing comment about datasource being optional.

This commit is contained in:
mike12345567 2024-06-19 12:03:20 +01:00
parent c973562398
commit abfab054d7
4 changed files with 10 additions and 8 deletions

View File

@ -33,5 +33,5 @@ export async function makeTableRequest(
if (renamed) { if (renamed) {
json.meta!.renamed = renamed json.meta!.renamed = renamed
} }
return makeExternalQuery(json, datasource) return makeExternalQuery(datasource, json)
} }

View File

@ -8,8 +8,8 @@ import { getIntegration } from "../index"
import sdk from "../../sdk" import sdk from "../../sdk"
export async function makeExternalQuery( export async function makeExternalQuery(
json: QueryJson, datasource: Datasource,
datasource?: Datasource json: QueryJson
): Promise<DatasourcePlusQueryResponse> { ): Promise<DatasourcePlusQueryResponse> {
const entityId = json.endpoint.entityId, const entityId = json.endpoint.entityId,
tableName = json.meta.table.name, tableName = json.meta.table.name,

View File

@ -11,10 +11,11 @@ import { SQS_DATASOURCE_INTERNAL } from "@budibase/backend-core"
import { getSQLClient } from "./utils" import { getSQLClient } from "./utils"
import { cloneDeep } from "lodash" import { cloneDeep } from "lodash"
import datasources from "../datasources" import datasources from "../datasources"
import { BudibaseInternalDB } from "../../../db/utils"
type PerformQueryFunction = ( type PerformQueryFunction = (
json: QueryJson, datasource: Datasource,
datasource?: Datasource json: QueryJson
) => Promise<DatasourcePlusQueryResponse> ) => Promise<DatasourcePlusQueryResponse>
const WRITE_OPERATIONS: Operation[] = [ const WRITE_OPERATIONS: Operation[] = [
@ -179,9 +180,10 @@ export default class AliasTables {
): Promise<DatasourcePlusQueryResponse> { ): Promise<DatasourcePlusQueryResponse> {
const datasourceId = json.endpoint.datasourceId const datasourceId = json.endpoint.datasourceId
const isSqs = datasourceId === SQS_DATASOURCE_INTERNAL const isSqs = datasourceId === SQS_DATASOURCE_INTERNAL
let aliasingEnabled: boolean, datasource: Datasource | undefined let aliasingEnabled: boolean, datasource: Datasource
if (isSqs) { if (isSqs) {
aliasingEnabled = this.isAliasingEnabled(json) aliasingEnabled = this.isAliasingEnabled(json)
datasource = BudibaseInternalDB
} else { } else {
datasource = await datasources.get(datasourceId) datasource = await datasources.get(datasourceId)
aliasingEnabled = this.isAliasingEnabled(json, datasource) aliasingEnabled = this.isAliasingEnabled(json, datasource)
@ -233,7 +235,7 @@ export default class AliasTables {
json.tableAliases = invertedTableAliases json.tableAliases = invertedTableAliases
} }
let response: DatasourcePlusQueryResponse = await queryFn(json, datasource) let response: DatasourcePlusQueryResponse = await queryFn(datasource, json)
if (Array.isArray(response) && aliasingEnabled) { if (Array.isArray(response) && aliasingEnabled) {
return this.reverse(response) return this.reverse(response)
} else { } else {

View File

@ -61,7 +61,7 @@ export async function getDatasourceAndQuery(
table, table,
} }
} }
return makeExternalQuery(json, datasource) return makeExternalQuery(datasource, json)
} }
export function cleanExportRows( export function cleanExportRows(