-
Notifications
You must be signed in to change notification settings - Fork 176
docs: Update query examples to use eq() helper for boolean comparisons #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,7 +831,7 @@ A complete todo application demonstrating validation, transformations, and defau | |
|
|
||
| ```typescript | ||
| import { z } from 'zod' | ||
| import { createCollection } from '@tanstack/react-db' | ||
| import { createCollection, eq } from '@tanstack/react-db' | ||
| import { queryCollectionOptions } from '@tanstack/query-db-collection' | ||
|
|
||
| // Schema with validation, transformations, and defaults | ||
|
|
@@ -921,7 +921,7 @@ const todoCollection = createCollection( | |
| function TodoApp() { | ||
| const { data: todos } = useLiveQuery(q => | ||
| q.from({ todo: todoCollection }) | ||
| .where(({ todo }) => !todo.completed) | ||
| .where(({ todo }) => eq(todo.completed, false)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing |
||
| .orderBy(({ todo }) => todo.created_at, 'desc') | ||
| ) | ||
|
|
||
|
|
@@ -991,6 +991,7 @@ function TodoApp() { | |
|
|
||
| ```typescript | ||
| import { z } from 'zod' | ||
| import { eq } from '@tanstack/db' | ||
|
|
||
| // Schema with computed fields and transformations | ||
| const productSchema = z.object({ | ||
|
|
@@ -1046,7 +1047,7 @@ const productCollection = createCollection( | |
| function ProductList() { | ||
| const { data: products } = useLiveQuery(q => | ||
| q.from({ product: productCollection }) | ||
| .where(({ product }) => product.in_stock) // Use computed field | ||
| .where(({ product }) => eq(product.in_stock, true)) // Use computed field | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normally, there should be no reason to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have an open PR #1304 that fixes this so let's write this in the idiomatic way in the docs and let's merge the docs when the PR is merged. |
||
| .orderBy(({ product }) => product.final_price, 'asc') | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,7 @@ const todoCollection = createCollection({ | |
| const Todos = () => { | ||
| // Bind data using live queries | ||
| const { data: todos } = useLiveQuery((q) => | ||
| q.from({ todo: todoCollection }).where(({ todo }) => todo.completed) | ||
| q.from({ todo: todoCollection }).where(({ todo }) => eq(todo.completed, false)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
| ) | ||
|
|
||
| const complete = (todo) => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not very idiomatic. Should be
not(todo.completed).