Skip to content

Commit be3921e

Browse files
kevin-dpclaude
andauthored
docs: Use idiomatic boolean filters in query examples (#1306)
docs: Use idiomatic boolean filters instead of eq() for boolean comparisons Replace eq(x, false) with not(x) and eq(x, true) with bare boolean refs in query examples, aligning docs with the idiomatic API supported by #1304. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e9d0fd8 commit be3921e

5 files changed

Lines changed: 12 additions & 11 deletions

File tree

docs/collections/trailbase-collection.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ const todosCollection = createCollection(
147147
## Complete Example
148148

149149
```typescript
150-
import { createCollection, eq } from '@tanstack/react-db'
150+
import { createCollection } from '@tanstack/react-db'
151+
import { not } from '@tanstack/db'
151152
import { trailBaseCollectionOptions } from '@tanstack/trailbase-db-collection'
152153
import { initClient } from 'trailbase'
153154
import { z } from 'zod'
@@ -195,7 +196,7 @@ export const todosCollection = createCollection<SelectTodo, Todo>(
195196
function TodoList() {
196197
const { data: todos } = useLiveQuery((q) =>
197198
q.from({ todo: todosCollection })
198-
.where(({ todo }) => eq(todo.completed, false))
199+
.where(({ todo }) => not(todo.completed))
199200
.orderBy(({ todo }) => todo.created_at, 'desc')
200201
)
201202

docs/guides/schemas.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,8 @@ A complete todo application demonstrating validation, transformations, and defau
831831

832832
```typescript
833833
import { z } from 'zod'
834-
import { createCollection, eq } from '@tanstack/react-db'
834+
import { createCollection } from '@tanstack/react-db'
835+
import { not } from '@tanstack/db'
835836
import { queryCollectionOptions } from '@tanstack/query-db-collection'
836837

837838
// Schema with validation, transformations, and defaults
@@ -921,7 +922,7 @@ const todoCollection = createCollection(
921922
function TodoApp() {
922923
const { data: todos } = useLiveQuery(q =>
923924
q.from({ todo: todoCollection })
924-
.where(({ todo }) => eq(todo.completed, false))
925+
.where(({ todo }) => not(todo.completed))
925926
.orderBy(({ todo }) => todo.created_at, 'desc')
926927
)
927928

@@ -991,7 +992,6 @@ function TodoApp() {
991992

992993
```typescript
993994
import { z } from 'zod'
994-
import { eq } from '@tanstack/db'
995995

996996
// Schema with computed fields and transformations
997997
const productSchema = z.object({
@@ -1047,7 +1047,7 @@ const productCollection = createCollection(
10471047
function ProductList() {
10481048
const { data: products } = useLiveQuery(q =>
10491049
q.from({ product: productCollection })
1050-
.where(({ product }) => eq(product.in_stock, true)) // Use computed field
1050+
.where(({ product }) => product.in_stock) // Use computed field
10511051
.orderBy(({ product }) => product.final_price, 'asc')
10521052
)
10531053

docs/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const todoCollection = createCollection({
5757
const Todos = () => {
5858
// Bind data using live queries
5959
const { data: todos } = useLiveQuery((q) =>
60-
q.from({ todo: todoCollection }).where(({ todo }) => eq(todo.completed, false))
60+
q.from({ todo: todoCollection }).where(({ todo }) => not(todo.completed))
6161
)
6262

6363
const complete = (todo) => {

docs/reference/classes/BaseQueryBuilder.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ A QueryBuilder with the specified source
288288
query.from({ users: usersCollection })
289289

290290
// Query from a subquery
291-
const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
291+
const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
292292
query.from({ activeUsers })
293293
```
294294

@@ -550,7 +550,7 @@ query
550550
```
551551

552552
// Join with a subquery
553-
const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
553+
const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
554554
query
555555
.from({ activeUsers })
556556
.join({ p: postsCollection }, ({u, p}) => eq(u.id, p.userId))

packages/db/src/query/builder/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
130130
* query.from({ users: usersCollection })
131131
*
132132
* // Query from a subquery
133-
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
133+
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
134134
* query.from({ activeUsers })
135135
* ```
136136
*/
@@ -172,7 +172,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
172172
* ```
173173
*
174174
* // Join with a subquery
175-
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
175+
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
176176
* query
177177
* .from({ activeUsers })
178178
* .join({ p: postsCollection }, ({u, p}) => eq(u.id, p.userId))

0 commit comments

Comments
 (0)