From f6ad53f442c8a4c93f37d37339d959c3496f6f51 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 28 Nov 2024 16:17:09 +0000 Subject: [PATCH] Follow-up PR to bigint fixes. --- .../server/src/api/controllers/datasource.ts | 2 -- .../server/src/integrations/base/query.ts | 34 +++++++++++++------ .../src/integrations/microsoftSqlServer.ts | 4 +-- packages/server/src/integrations/oracle.ts | 6 +--- .../src/integrations/tests/sqlAlias.spec.ts | 2 +- .../src/tests/utilities/api/datasource.ts | 1 - 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index 42d657cf6c..97cf8db299 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -23,13 +23,11 @@ import { Table, RowValue, DynamicVariable, - QueryJsonRequest, } from "@budibase/types" import sdk from "../../sdk" import { builderSocket } from "../../websockets" import { isEqual } from "lodash" import { processTable } from "../../sdk/app/tables/getters" -import { makeExternalQuery } from "../../integrations/base/query" export async function fetch(ctx: UserCtx) { ctx.body = await sdk.datasources.fetch() diff --git a/packages/server/src/integrations/base/query.ts b/packages/server/src/integrations/base/query.ts index 6555a5de51..2cbbbecc8d 100644 --- a/packages/server/src/integrations/base/query.ts +++ b/packages/server/src/integrations/base/query.ts @@ -1,27 +1,39 @@ -import { DatasourcePlusQueryResponse, QueryJson } from "@budibase/types" +import { + DatasourcePlusQueryResponse, + EnrichedQueryJson, + QueryJson, +} from "@budibase/types" import { getIntegration } from "../index" import sdk from "../../sdk" import { enrichQueryJson } from "../../sdk/app/rows/utils" +function isEnriched( + json: QueryJson | EnrichedQueryJson +): json is EnrichedQueryJson { + return "datasource" in json +} + export async function makeExternalQuery( - json: QueryJson + json: QueryJson | EnrichedQueryJson ): Promise { - const enrichedJson = await enrichQueryJson(json) - if (!enrichedJson.datasource) { + if (!isEnriched(json)) { + json = await enrichQueryJson(json) + if (json.datasource) { + json.datasource = await sdk.datasources.enrich(json.datasource) + } + } + + if (!json.datasource) { throw new Error("No datasource provided for external query") } - enrichedJson.datasource = await sdk.datasources.enrich( - enrichedJson.datasource - ) - - const Integration = await getIntegration(enrichedJson.datasource.source) + const Integration = await getIntegration(json.datasource.source) // query is the opinionated function if (!Integration.prototype.query) { throw "Datasource does not support query." } - const integration = new Integration(enrichedJson.datasource.config) - return integration.query(enrichedJson) + const integration = new Integration(json.datasource.config) + return integration.query(json) } diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index a7a0b53312..2fac306590 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -509,8 +509,8 @@ class SqlServerIntegration extends Sql implements DatasourcePlus { async query(json: EnrichedQueryJson): Promise { const schema = this.config.schema await this.connect() - if (schema && schema !== DEFAULT_SCHEMA && json?.endpoint) { - json.endpoint.schema = schema + if (schema && schema !== DEFAULT_SCHEMA) { + json.schema = schema } const operation = this._operation(json) const queryFn = (query: any, op: string) => this.internalQuery(query, op) diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index ded21487f6..d8708d9053 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -572,11 +572,7 @@ class OracleIntegration extends Sql implements DatasourcePlus { return response.rows as Row[] } else { // get the last row that was updated - if ( - response.lastRowid && - json.endpoint?.entityId && - operation !== Operation.DELETE - ) { + if (response.lastRowid && operation !== Operation.DELETE) { const lastRow = await this.internalQuery({ sql: `SELECT * FROM "${json.table.name}" WHERE ROWID = '${response.lastRowid}'`, }) diff --git a/packages/server/src/integrations/tests/sqlAlias.spec.ts b/packages/server/src/integrations/tests/sqlAlias.spec.ts index 4de84f689e..0f43e41755 100644 --- a/packages/server/src/integrations/tests/sqlAlias.spec.ts +++ b/packages/server/src/integrations/tests/sqlAlias.spec.ts @@ -269,7 +269,7 @@ describe("Captures of real examples", () => { fields: string[] = ["a"] ): EnrichedQueryJson { return { - endpoint: { datasourceId: "", entityId: "", operation: op }, + operation: op, resource: { fields, }, diff --git a/packages/server/src/tests/utilities/api/datasource.ts b/packages/server/src/tests/utilities/api/datasource.ts index ebd1b9f7c7..0bc365661e 100644 --- a/packages/server/src/tests/utilities/api/datasource.ts +++ b/packages/server/src/tests/utilities/api/datasource.ts @@ -4,7 +4,6 @@ import { Datasource, FetchDatasourceInfoResponse, FieldType, - QueryJsonRequest, RelationshipType, UpdateDatasourceRequest, UpdateDatasourceResponse,