Follow-up PR to bigint fixes.

This commit is contained in:
Sam Rose 2024-11-28 16:17:09 +00:00
parent b17c6ab43a
commit f6ad53f442
No known key found for this signature in database
6 changed files with 27 additions and 22 deletions

View File

@ -23,13 +23,11 @@ import {
Table, Table,
RowValue, RowValue,
DynamicVariable, DynamicVariable,
QueryJsonRequest,
} from "@budibase/types" } from "@budibase/types"
import sdk from "../../sdk" import sdk from "../../sdk"
import { builderSocket } from "../../websockets" import { builderSocket } from "../../websockets"
import { isEqual } from "lodash" import { isEqual } from "lodash"
import { processTable } from "../../sdk/app/tables/getters" import { processTable } from "../../sdk/app/tables/getters"
import { makeExternalQuery } from "../../integrations/base/query"
export async function fetch(ctx: UserCtx) { export async function fetch(ctx: UserCtx) {
ctx.body = await sdk.datasources.fetch() ctx.body = await sdk.datasources.fetch()

View File

@ -1,27 +1,39 @@
import { DatasourcePlusQueryResponse, QueryJson } from "@budibase/types" import {
DatasourcePlusQueryResponse,
EnrichedQueryJson,
QueryJson,
} from "@budibase/types"
import { getIntegration } from "../index" import { getIntegration } from "../index"
import sdk from "../../sdk" import sdk from "../../sdk"
import { enrichQueryJson } from "../../sdk/app/rows/utils" import { enrichQueryJson } from "../../sdk/app/rows/utils"
function isEnriched(
json: QueryJson | EnrichedQueryJson
): json is EnrichedQueryJson {
return "datasource" in json
}
export async function makeExternalQuery( export async function makeExternalQuery(
json: QueryJson json: QueryJson | EnrichedQueryJson
): Promise<DatasourcePlusQueryResponse> { ): Promise<DatasourcePlusQueryResponse> {
const enrichedJson = await enrichQueryJson(json) if (!isEnriched(json)) {
if (!enrichedJson.datasource) { 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") throw new Error("No datasource provided for external query")
} }
enrichedJson.datasource = await sdk.datasources.enrich( const Integration = await getIntegration(json.datasource.source)
enrichedJson.datasource
)
const Integration = await getIntegration(enrichedJson.datasource.source)
// query is the opinionated function // query is the opinionated function
if (!Integration.prototype.query) { if (!Integration.prototype.query) {
throw "Datasource does not support query." throw "Datasource does not support query."
} }
const integration = new Integration(enrichedJson.datasource.config) const integration = new Integration(json.datasource.config)
return integration.query(enrichedJson) return integration.query(json)
} }

View File

@ -509,8 +509,8 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
async query(json: EnrichedQueryJson): Promise<DatasourcePlusQueryResponse> { async query(json: EnrichedQueryJson): Promise<DatasourcePlusQueryResponse> {
const schema = this.config.schema const schema = this.config.schema
await this.connect() await this.connect()
if (schema && schema !== DEFAULT_SCHEMA && json?.endpoint) { if (schema && schema !== DEFAULT_SCHEMA) {
json.endpoint.schema = schema json.schema = schema
} }
const operation = this._operation(json) const operation = this._operation(json)
const queryFn = (query: any, op: string) => this.internalQuery(query, op) const queryFn = (query: any, op: string) => this.internalQuery(query, op)

View File

@ -572,11 +572,7 @@ class OracleIntegration extends Sql implements DatasourcePlus {
return response.rows as Row[] return response.rows as Row[]
} else { } else {
// get the last row that was updated // get the last row that was updated
if ( if (response.lastRowid && operation !== Operation.DELETE) {
response.lastRowid &&
json.endpoint?.entityId &&
operation !== Operation.DELETE
) {
const lastRow = await this.internalQuery({ const lastRow = await this.internalQuery({
sql: `SELECT * FROM "${json.table.name}" WHERE ROWID = '${response.lastRowid}'`, sql: `SELECT * FROM "${json.table.name}" WHERE ROWID = '${response.lastRowid}'`,
}) })

View File

@ -269,7 +269,7 @@ describe("Captures of real examples", () => {
fields: string[] = ["a"] fields: string[] = ["a"]
): EnrichedQueryJson { ): EnrichedQueryJson {
return { return {
endpoint: { datasourceId: "", entityId: "", operation: op }, operation: op,
resource: { resource: {
fields, fields,
}, },

View File

@ -4,7 +4,6 @@ import {
Datasource, Datasource,
FetchDatasourceInfoResponse, FetchDatasourceInfoResponse,
FieldType, FieldType,
QueryJsonRequest,
RelationshipType, RelationshipType,
UpdateDatasourceRequest, UpdateDatasourceRequest,
UpdateDatasourceResponse, UpdateDatasourceResponse,