Skip to content

Commit 15cffca

Browse files
committed
Handle subset that is false
1 parent b6f8a02 commit 15cffca

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/db/src/query/predicate-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ function isWhereSubsetInternal(
6666
subset: BasicExpression<boolean>,
6767
superset: BasicExpression<boolean>
6868
): boolean {
69+
// If subset is false it is requesting no data,
70+
// thus the result set is empty
71+
// and the empty set is a subset of any set
72+
if (subset.type === `val` && subset.value === false) {
73+
return true
74+
}
75+
6976
// If expressions are structurally equal, subset relationship holds
7077
if (areExpressionsEqual(subset, superset)) {
7178
return true

packages/db/tests/predicate-utils.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ describe(`isWhereSubset`, () => {
9696
isWhereSubset(gt(ref(`age`), val(10)), gt(ref(`age`), val(10)))
9797
).toBe(true)
9898
})
99+
100+
it(`should return true when subset is false`, () => {
101+
// When subset is false the result will always be the empty set
102+
// and the empty set is a subset of any set
103+
expect(isWhereSubset(val(false), gt(ref(`age`), val(10)))).toBe(true)
104+
})
99105
})
100106

101107
describe(`comparison operators`, () => {

0 commit comments

Comments
 (0)