Open History to see the last commit
1---
2id: extractSimpleComparisons
3title: extractSimpleComparisons
4---
5
6```ts
7function extractSimpleComparisons(expr): SimpleComparison[];
8```
9
10Defined in: [packages/db/src/query/expression-helpers.ts:337](https://github.com/TanStack/db/blob/main/packages/db/src/query/expression-helpers.ts#L337)
11
12Extracts all simple comparisons from a WHERE expression.
13This is useful for simple APIs that only support basic filters.
14
15Note: This only works for simple AND-ed conditions and NOT-wrapped comparisons.
16Throws an error if it encounters unsupported operations like OR or complex nested expressions.
17
18NOT operators are flattened by prefixing the operator name (e.g., `not(eq(...))` becomes `not_eq`).
19
20## Parameters
21
22### expr
23
24The WHERE expression to parse
25
26`BasicExpression`\<`boolean`\> | `null` | `undefined`
27
28## Returns
29
30[`SimpleComparison`](../interfaces/SimpleComparison.md)[]
31
32Array of simple comparisons
33
34## Throws
35
36Error if expression contains OR or other unsupported operations
37
38## Example
39
40```typescript
41const comparisons = extractSimpleComparisons(where)
42// Returns: [
43// { field: ['category'], operator: 'eq', value: 'electronics' },
44// { field: ['price'], operator: 'lt', value: 100 },
45// { field: ['email'], operator: 'isNull' }, // No value for null checks
46// { field: ['status'], operator: 'not_eq', value: 'archived' }
47// ]
48```