From f21199011788c2f6e69e77d5ea983f3f8662961b Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 26 Nov 2024 17:36:17 +0000 Subject: [PATCH] Some sqs fixes. --- packages/backend-core/src/sql/sql.ts | 13 ++++++++++--- packages/server/src/api/controllers/datasource.ts | 2 +- packages/server/src/api/routes/tests/row.spec.ts | 2 +- .../server/src/sdk/app/rows/search/internal/sqs.ts | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 5333bfb591..baeeefbb81 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -3,6 +3,7 @@ import * as dbCore from "../db" import { getNativeSql, isExternalTable, + isInternalTableID, isInvalidISODateString, isValidFilter, isValidISODateString, @@ -1192,7 +1193,7 @@ class InternalBuilder { private buildJsonField(table: Table, field: string): [string, Knex.Raw] { const parts = field.split(".") - const baseName = parts[parts.length - 1] + let baseName = parts[parts.length - 1] let unaliased: string let tableField: string @@ -1205,10 +1206,16 @@ class InternalBuilder { tableField = unaliased } - const schema = table.schema[baseName] + if (this.query.meta?.columnPrefix) { + baseName = baseName.replace(this.query.meta.columnPrefix, "") + } let identifier = this.rawQuotedIdentifier(tableField) - if (schema.type === FieldType.BIGINT) { + // Internal tables have special _id, _rev, createdAt, and updatedAt fields + // that do not appear in the schema, meaning schema could actually be + // undefined. + const schema: FieldSchema | undefined = table.schema[baseName] + if (schema && schema.type === FieldType.BIGINT) { identifier = this.castIntToString(identifier) } return [unaliased, identifier] diff --git a/packages/server/src/api/controllers/datasource.ts b/packages/server/src/api/controllers/datasource.ts index 9f4fff4c46..01d81425b6 100644 --- a/packages/server/src/api/controllers/datasource.ts +++ b/packages/server/src/api/controllers/datasource.ts @@ -29,7 +29,7 @@ import sdk from "../../sdk" import { builderSocket } from "../../websockets" import { isEqual } from "lodash" import { processTable } from "../../sdk/app/tables/getters" -import { makeExternalQuery } from "src/integrations/base/query" +import { makeExternalQuery } from "../../integrations/base/query" export async function fetch(ctx: UserCtx) { ctx.body = await sdk.datasources.fetch() diff --git a/packages/server/src/api/routes/tests/row.spec.ts b/packages/server/src/api/routes/tests/row.spec.ts index 9e84e74d05..1ab12feebb 100644 --- a/packages/server/src/api/routes/tests/row.spec.ts +++ b/packages/server/src/api/routes/tests/row.spec.ts @@ -3333,7 +3333,7 @@ if (descriptions.length) { }) isInternal && - it("should coerce a static handlebars formula", async () => { + it.only("should coerce a static handlebars formula", async () => { await updateFormulaColumn(encodeJS("return 1"), { responseType: FieldType.NUMBER, formulaType: FormulaType.STATIC, diff --git a/packages/server/src/sdk/app/rows/search/internal/sqs.ts b/packages/server/src/sdk/app/rows/search/internal/sqs.ts index a12b842afc..aec934ae4e 100644 --- a/packages/server/src/sdk/app/rows/search/internal/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/internal/sqs.ts @@ -494,6 +494,7 @@ export async function search( if (err.status === 400 && msg?.match(MISSING_COLUMN_REGEX)) { return { rows: [] } } - throw new Error(`Unable to search by SQL - ${msg}`, { cause: err }) + // throw new Error(`Unable to search by SQL - ${msg}`, { cause: err }) + throw err } }