Merge pull request #3558 from Budibase/fix/enrich-sql

Fixing SQL enrichment issue
This commit is contained in:
Michael Drury 2021-11-26 17:43:14 +00:00 committed by GitHub
commit 415689c303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { import {
FilterTypes,
IncludeRelationships, IncludeRelationships,
Operation, Operation,
PaginationJson, PaginationJson,
@ -118,8 +119,13 @@ module External {
} }
// check the row and filters to make sure they aren't a key of some sort // check the row and filters to make sure they aren't a key of some sort
if (config.filters) { if (config.filters) {
for (let filter of Object.values(config.filters)) { for (let [key, filter] of Object.entries(config.filters)) {
if (typeof filter !== "object" || Object.keys(filter).length === 0) { // oneOf is an array, don't iterate it
if (
typeof filter !== "object" ||
Object.keys(filter).length === 0 ||
key === FilterTypes.ONE_OF
) {
continue continue
} }
iterateObject(filter) iterateObject(filter)

View File

@ -54,6 +54,17 @@ export enum IncludeRelationships {
EXCLUDE = 0, EXCLUDE = 0,
} }
export enum FilterTypes {
STRING = "string",
FUZZY = "fuzzy",
RANGE = "range",
EQUAL = "equal",
NOT_EQUAL = "notEqual",
EMPTY = "empty",
NOT_EMPTY = "notEmpty",
ONE_OF = "oneOf",
}
export interface QueryDefinition { export interface QueryDefinition {
type: QueryTypes type: QueryTypes
displayName?: string displayName?: string

View File

@ -93,7 +93,7 @@ class InternalBuilder {
if (filters.oneOf) { if (filters.oneOf) {
iterate(filters.oneOf, (key, array) => { iterate(filters.oneOf, (key, array) => {
const fnc = allOr ? "orWhereIn" : "whereIn" const fnc = allOr ? "orWhereIn" : "whereIn"
query = query[fnc](key, array) query = query[fnc](key, Array.isArray(array) ? array : [array])
}) })
} }
if (filters.string) { if (filters.string) {