Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

isWhereSubset.md

47 lines1.2 KB

1---
2id: isWhereSubset
3title: isWhereSubset
4---
5​
6# Function: isWhereSubset()
7​
8```ts
9function isWhereSubset(subset, superset): boolean;
10```
11​
12Defined in: [packages/db/src/query/predicate-utils.ts:21](https://github.com/TanStack/db/blob/main/packages/db/src/query/predicate-utils.ts#L21)
13​
14Check if one where clause is a logical subset of another.
15Returns true if the subset predicate is more restrictive than (or equal to) the superset predicate.
16​
17## Parameters
18​
19### subset
20​
21The potentially more restrictive predicate
22​
23[`BasicExpression`](../@tanstack/namespaces/IR/type-aliases/BasicExpression.md)\<`boolean`\> | `undefined`
24​
25### superset
26​
27The potentially less restrictive predicate
28​
29[`BasicExpression`](../@tanstack/namespaces/IR/type-aliases/BasicExpression.md)\<`boolean`\> | `undefined`
30​
31## Returns
32​
33`boolean`
34​
35true if subset logically implies superset
36​
37## Examples
38​
39```ts
40// age > 20 is subset of age > 10 (more restrictive)
41isWhereSubset(gt(ref('age'), val(20)), gt(ref('age'), val(10))) // true
42```
43​
44```ts
45// age > 10 AND name = 'X' is subset of age > 10 (more conditions)
46isWhereSubset(and(gt(ref('age'), val(10)), eq(ref('name'), val('X'))), gt(ref('age'), val(10))) // true
47```