Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/collections/trailbase-collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const todosCollection = createCollection(
## Complete Example

```typescript
import { createCollection } from '@tanstack/react-db'
import { createCollection, eq } from '@tanstack/react-db'
import { trailBaseCollectionOptions } from '@tanstack/trailbase-db-collection'
import { initClient } from 'trailbase'
import { z } from 'zod'
Expand Down Expand Up @@ -195,7 +195,7 @@ export const todosCollection = createCollection<SelectTodo, Todo>(
function TodoList() {
const { data: todos } = useLiveQuery((q) =>
q.from({ todo: todosCollection })
.where(({ todo }) => !todo.completed)
.where(({ todo }) => eq(todo.completed, false))
Copy link
Contributor

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).

.orderBy(({ todo }) => todo.created_at, 'desc')
)

Expand Down
7 changes: 4 additions & 3 deletions docs/guides/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing

.orderBy(({ todo }) => todo.created_at, 'desc')
)

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, there should be no reason to use eq here and just product.in_stock should work as it is a boolean, but i know we don't support that yet... It should be though. I'll open an issue for it.

Copy link
Contributor

Choose a reason for hiding this comment

The 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')
)

Expand Down
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be not(todo.completed)

)

const complete = (todo) => {
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/classes/BaseQueryBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ A QueryBuilder with the specified source
query.from({ users: usersCollection })

// Query from a subquery
const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
query.from({ activeUsers })
```

Expand Down Expand Up @@ -550,7 +550,7 @@ query
```

// Join with a subquery
const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
query
.from({ activeUsers })
.join({ p: postsCollection }, ({u, p}) => eq(u.id, p.userId))
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/query/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
* query.from({ users: usersCollection })
*
* // Query from a subquery
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
* query.from({ activeUsers })
* ```
*/
Expand Down Expand Up @@ -171,7 +171,7 @@ export class BaseQueryBuilder<TContext extends Context = Context> {
* ```
*
* // Join with a subquery
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => u.active)
* const activeUsers = query.from({ u: usersCollection }).where(({u}) => eq(u.active, true))
* query
* .from({ activeUsers })
* .join({ p: postsCollection }, ({u, p}) => eq(u.id, p.userId))
Expand Down
Loading