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