Merge pull request #14331 from Budibase/BUDI-8506/in-memory-support-for-logical-operators
In-memory support for logical operators
This commit is contained in:
commit
99a026172b
|
@ -2697,7 +2697,7 @@ describe.each([
|
|||
})
|
||||
})
|
||||
|
||||
isSql &&
|
||||
!isLucene &&
|
||||
describe("$and", () => {
|
||||
beforeAll(async () => {
|
||||
table = await createTable({
|
||||
|
@ -2771,7 +2771,7 @@ describe.each([
|
|||
})
|
||||
})
|
||||
|
||||
isSql &&
|
||||
!isLucene &&
|
||||
describe("$or", () => {
|
||||
beforeAll(async () => {
|
||||
table = await createTable({
|
||||
|
|
|
@ -464,14 +464,18 @@ export const runQuery = (docs: Record<string, any>[], query: SearchFilters) => {
|
|||
) =>
|
||||
(doc: Record<string, any>) => {
|
||||
for (const [key, testValue] of Object.entries(query[type] || {})) {
|
||||
const result = test(deepGet(doc, removeKeyNumbering(key)), testValue)
|
||||
const valueToCheck =
|
||||
type === LogicalOperator.AND || type === LogicalOperator.OR
|
||||
? doc
|
||||
: deepGet(doc, removeKeyNumbering(key))
|
||||
const result = test(valueToCheck, testValue)
|
||||
if (query.allOr && result) {
|
||||
return true
|
||||
} else if (!query.allOr && !result) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return !query.allOr
|
||||
}
|
||||
|
||||
const stringMatch = match(
|
||||
|
@ -674,15 +678,34 @@ export const runQuery = (docs: Record<string, any>[], query: SearchFilters) => {
|
|||
|
||||
const and = match(
|
||||
LogicalOperator.AND,
|
||||
(_docValue: Record<string, any>, _testValue: any) => {
|
||||
// TODO
|
||||
return false
|
||||
(docValue: Record<string, any>, conditions: SearchFilters[]) => {
|
||||
if (!conditions.length) {
|
||||
return false
|
||||
}
|
||||
for (const condition of conditions) {
|
||||
const matchesCondition = runQuery([docValue], condition)
|
||||
if (!matchesCondition.length) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
)
|
||||
const or = match(
|
||||
LogicalOperator.AND,
|
||||
(_docValue: Record<string, any>, _testValue: any) => {
|
||||
// TODO
|
||||
LogicalOperator.OR,
|
||||
(docValue: Record<string, any>, conditions: SearchFilters[]) => {
|
||||
if (!conditions.length) {
|
||||
return false
|
||||
}
|
||||
for (const condition of conditions) {
|
||||
const matchesCondition = runQuery([docValue], {
|
||||
...condition,
|
||||
allOr: true,
|
||||
})
|
||||
if (matchesCondition.length) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue