From 48486cdaa4aa8bdc664b8ee33ea4fabab4f74452 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 9 Aug 2024 13:14:16 +0200 Subject: [PATCH] Implement query --- packages/server/src/sdk/app/rows/search.ts | 6 ++++ .../sdk/app/rows/search/tests/search.spec.ts | 31 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index ea0b3bf5b6..e840c1ca51 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -14,6 +14,7 @@ import sdk from "../../index" import { searchInputMapping } from "./search/utils" import { db as dbCore } from "@budibase/backend-core" import tracer from "dd-trace" +import { removeInvalidFilters } from "./queryUtils" export { isValidFilter } from "../../../integrations/utils" @@ -86,6 +87,11 @@ export async function search( options.fields = visibleTableFields } + options.query = removeInvalidFilters(options.query, [ + "_id", + ...options.fields, + ]) + let result: SearchResponse if (isExternalTable) { span?.addTags({ searchType: "external" }) diff --git a/packages/server/src/sdk/app/rows/search/tests/search.spec.ts b/packages/server/src/sdk/app/rows/search/tests/search.spec.ts index 235598cc40..510aa209a8 100644 --- a/packages/server/src/sdk/app/rows/search/tests/search.spec.ts +++ b/packages/server/src/sdk/app/rows/search/tests/search.spec.ts @@ -1,4 +1,11 @@ -import { Datasource, FieldType, Table } from "@budibase/types" +import { + AutoColumnFieldMetadata, + AutoFieldSubType, + Datasource, + FieldType, + NumberFieldMetadata, + Table, +} from "@budibase/types" import TestConfiguration from "../../../../../tests/utilities/TestConfiguration" import { search } from "../../../../../sdk/app/rows/search" @@ -53,15 +60,25 @@ describe.each([ }) beforeEach(async () => { + const idFieldSchema: NumberFieldMetadata | AutoColumnFieldMetadata = + isInternal + ? { + name: "id", + type: FieldType.AUTO, + subtype: AutoFieldSubType.AUTO_ID, + autocolumn: true, + } + : { + name: "id", + type: FieldType.NUMBER, + autocolumn: true, + } + table = await config.api.table.save( tableForDatasource(datasource, { primary: ["id"], schema: { - id: { - name: "id", - type: FieldType.NUMBER, - autocolumn: true, - }, + id: idFieldSchema, name: { name: "name", type: FieldType.STRING, @@ -256,7 +273,7 @@ describe.each([ [["id", "name", "age"], 3], [["name", "age"], 10], ])( - "cannot query by non search fields", + "cannot query by non search fields (fields: %s)", async (queryFields, expectedRows) => { await config.doInContext(config.appId, async () => { const { rows } = await search({