diff --git a/packages/server/src/api/controllers/row/external.ts b/packages/server/src/api/controllers/row/external.ts index 8ce9ff0f9d..e0e3cb6c18 100644 --- a/packages/server/src/api/controllers/row/external.ts +++ b/packages/server/src/api/controllers/row/external.ts @@ -17,11 +17,9 @@ import { Row, Table, UserCtx, - EmptyFilterOption, } from "@budibase/types" import sdk from "../../../sdk" import * as utils from "./utils" -import { dataFilters } from "@budibase/shared-core" import { inputProcessing, outputProcessing, @@ -33,17 +31,6 @@ export async function handleRequest( tableId: string, opts?: RunConfig ): Promise> { - // make sure the filters are cleaned up, no empty strings for equals, fuzzy or string - if (opts && opts.filters) { - opts.filters = sdk.rows.removeEmptyFilters(opts.filters) - } - if ( - !dataFilters.hasFilters(opts?.filters) && - opts?.filters?.onEmptyFilter === EmptyFilterOption.RETURN_NONE - ) { - return [] as any - } - return new ExternalRequest(operation, tableId, opts?.datasource).run( opts || {} ) diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index abf12b35b2..f5828f9419 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -22,7 +22,6 @@ import { SortDirection, SqlQueryBinding, Table, - EmptyFilterOption, } from "@budibase/types" import environment from "../../environment" @@ -244,7 +243,6 @@ class InternalBuilder { return query } filters = parseFilters(filters) - let noFilters = true // if all or specified in filters, then everything is an or const allOr = filters.allOr if (filters.oneOf) { @@ -252,7 +250,6 @@ class InternalBuilder { const fnc = allOr ? "orWhereIn" : "whereIn" query = query[fnc](key, Array.isArray(array) ? array : [array]) }) - noFilters = false } if (filters.string) { iterate(filters.string, (key, value) => { @@ -268,11 +265,9 @@ class InternalBuilder { ]) } }) - noFilters = false } if (filters.fuzzy) { iterate(filters.fuzzy, like) - noFilters = false } if (filters.range) { iterate(filters.range, (key, value) => { @@ -305,59 +300,39 @@ class InternalBuilder { query = query[fnc](key, "<", value.high) } }) - noFilters = false } if (filters.equal) { iterate(filters.equal, (key, value) => { const fnc = allOr ? "orWhere" : "where" query = query[fnc]({ [key]: value }) }) - - // Somewhere above us in the stack adds `{ type: "row" }` to the `equal` - // key before we get here, so we need to still consider it empty when - // that's the case. - const equalEmpty = - Object.keys(filters.equal).length === 1 && filters.equal.type === "row" - if (!equalEmpty) { - noFilters = false - } } if (filters.notEqual) { iterate(filters.notEqual, (key, value) => { const fnc = allOr ? "orWhereNot" : "whereNot" query = query[fnc]({ [key]: value }) }) - noFilters = false } if (filters.empty) { iterate(filters.empty, key => { const fnc = allOr ? "orWhereNull" : "whereNull" query = query[fnc](key) }) - noFilters = false } if (filters.notEmpty) { iterate(filters.notEmpty, key => { const fnc = allOr ? "orWhereNotNull" : "whereNotNull" query = query[fnc](key) }) - noFilters = false } if (filters.contains) { contains(filters.contains) - noFilters = false } if (filters.notContains) { contains(filters.notContains) - noFilters = false } if (filters.containsAny) { contains(filters.containsAny, true) - noFilters = false - } - - if (noFilters && filters.onEmptyFilter === EmptyFilterOption.RETURN_NONE) { - query = query.whereRaw("1=0") } return query diff --git a/packages/server/src/sdk/app/rows/search.ts b/packages/server/src/sdk/app/rows/search.ts index 928c0f6780..65fd19e427 100644 --- a/packages/server/src/sdk/app/rows/search.ts +++ b/packages/server/src/sdk/app/rows/search.ts @@ -1,4 +1,5 @@ import { + EmptyFilterOption, Row, RowSearchParams, SearchFilters, @@ -11,6 +12,7 @@ import { NoEmptyFilterStrings } from "../../../constants" import * as sqs from "./search/sqs" import env from "../../../environment" import { ExportRowsParams, ExportRowsResult } from "./search/types" +import { dataFilters } from "@budibase/shared-core" export { isValidFilter } from "../../../integrations/utils" @@ -60,6 +62,16 @@ export async function search( options: RowSearchParams ): Promise> { const isExternalTable = isExternalTableID(options.tableId) + options.query = removeEmptyFilters(options.query) + if ( + !dataFilters.hasFilters(options.query) && + options.query.onEmptyFilter === EmptyFilterOption.RETURN_NONE + ) { + return { + rows: [], + } + } + if (isExternalTable) { return external.search(options) } else if (env.SQS_SEARCH_ENABLE) {