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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: queryCollectionOptions
function queryCollectionOptions<T, TQueryFn, TError, TQueryKey, TKey, TQueryData>(config): CollectionConfig<InferSchemaOutput<T>, TKey, T, QueryCollectionUtils<InferSchemaOutput<T>, TKey, InferSchemaInput<T>, TError>> & object;
```

Defined in: [packages/query-db-collection/src/query.ts:393](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L393)
Defined in: [packages/query-db-collection/src/query.ts:422](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L422)

Creates query collection options for use with a standard Collection.
This integrates TanStack Query with TanStack DB for automatic synchronization.
Expand Down Expand Up @@ -151,7 +151,7 @@ const todosCollection = createCollection(
function queryCollectionOptions<T, TQueryFn, TError, TQueryKey, TKey, TQueryData>(config): CollectionConfig<T, TKey, never, QueryCollectionUtils<T, TKey, T, TError>> & object;
```

Defined in: [packages/query-db-collection/src/query.ts:428](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L428)
Defined in: [packages/query-db-collection/src/query.ts:457](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L457)

Creates query collection options for use with a standard Collection.
This integrates TanStack Query with TanStack DB for automatic synchronization.
Expand Down Expand Up @@ -291,7 +291,7 @@ const todosCollection = createCollection(
function queryCollectionOptions<T, TError, TQueryKey, TKey>(config): CollectionConfig<InferSchemaOutput<T>, TKey, T, QueryCollectionUtils<InferSchemaOutput<T>, TKey, InferSchemaInput<T>, TError>> & object;
```

Defined in: [packages/query-db-collection/src/query.ts:461](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L461)
Defined in: [packages/query-db-collection/src/query.ts:490](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L490)

Creates query collection options for use with a standard Collection.
This integrates TanStack Query with TanStack DB for automatic synchronization.
Expand Down Expand Up @@ -423,7 +423,7 @@ const todosCollection = createCollection(
function queryCollectionOptions<T, TError, TQueryKey, TKey>(config): CollectionConfig<T, TKey, never, QueryCollectionUtils<T, TKey, T, TError>> & object;
```

Defined in: [packages/query-db-collection/src/query.ts:495](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L495)
Defined in: [packages/query-db-collection/src/query.ts:524](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L524)

Creates query collection options for use with a standard Collection.
This integrates TanStack Query with TanStack DB for automatic synchronization.
Expand Down
1 change: 1 addition & 0 deletions docs/reference/query-db-collection/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ title: "@tanstack/query-db-collection"

## Type Aliases

- [QueryCollectionMeta](../type-aliases/QueryCollectionMeta.md)
- [SyncOperation](../type-aliases/SyncOperation.md)

## Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: QueryCollectionConfig

# Interface: QueryCollectionConfig\<T, TQueryFn, TError, TQueryKey, TKey, TSchema, TQueryData\>

Defined in: [packages/query-db-collection/src/query.ts:59](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L59)
Defined in: [packages/query-db-collection/src/query.ts:88](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L88)

Configuration options for creating a Query Collection

Expand Down Expand Up @@ -63,7 +63,7 @@ The schema type for validation
optional enabled: boolean;
```

Defined in: [packages/query-db-collection/src/query.ts:85](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L85)
Defined in: [packages/query-db-collection/src/query.ts:114](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L114)

Whether the query should automatically run (default: true)

Expand All @@ -75,7 +75,7 @@ Whether the query should automatically run (default: true)
optional meta: Record<string, unknown>;
```

Defined in: [packages/query-db-collection/src/query.ts:135](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L135)
Defined in: [packages/query-db-collection/src/query.ts:164](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L164)

Metadata to pass to the query.
Available in queryFn via context.meta
Expand Down Expand Up @@ -107,7 +107,7 @@ meta: {
queryClient: QueryClient;
```

Defined in: [packages/query-db-collection/src/query.ts:81](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L81)
Defined in: [packages/query-db-collection/src/query.ts:110](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L110)

The TanStack Query client instance

Expand All @@ -119,7 +119,7 @@ The TanStack Query client instance
queryFn: TQueryFn extends (context) => Promise<any[]> ? (context) => Promise<T[]> : TQueryFn;
```

Defined in: [packages/query-db-collection/src/query.ts:73](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L73)
Defined in: [packages/query-db-collection/src/query.ts:102](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L102)

Function that fetches data from the server. Must return the complete collection state

Expand All @@ -131,7 +131,7 @@ Function that fetches data from the server. Must return the complete collection
queryKey: TQueryKey | TQueryKeyBuilder<TQueryKey>;
```

Defined in: [packages/query-db-collection/src/query.ts:71](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L71)
Defined in: [packages/query-db-collection/src/query.ts:100](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L100)

The query key used by TanStack Query to identify this query

Expand All @@ -143,7 +143,7 @@ The query key used by TanStack Query to identify this query
optional refetchInterval: number | false | (query) => number | false | undefined;
```

Defined in: [packages/query-db-collection/src/query.ts:86](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L86)
Defined in: [packages/query-db-collection/src/query.ts:115](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L115)

***

Expand All @@ -153,7 +153,7 @@ Defined in: [packages/query-db-collection/src/query.ts:86](https://github.com/Ta
optional retry: RetryValue<TError>;
```

Defined in: [packages/query-db-collection/src/query.ts:93](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L93)
Defined in: [packages/query-db-collection/src/query.ts:122](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L122)

***

Expand All @@ -163,7 +163,7 @@ Defined in: [packages/query-db-collection/src/query.ts:93](https://github.com/Ta
optional retryDelay: RetryDelayValue<TError>;
```

Defined in: [packages/query-db-collection/src/query.ts:100](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L100)
Defined in: [packages/query-db-collection/src/query.ts:129](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L129)

***

Expand All @@ -173,7 +173,7 @@ Defined in: [packages/query-db-collection/src/query.ts:100](https://github.com/T
optional select: (data) => T[];
```

Defined in: [packages/query-db-collection/src/query.ts:79](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L79)
Defined in: [packages/query-db-collection/src/query.ts:108](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L108)

#### Parameters

Expand All @@ -193,4 +193,4 @@ Defined in: [packages/query-db-collection/src/query.ts:79](https://github.com/Ta
optional staleTime: StaleTimeFunction<T[], TError, T[], TQueryKey>;
```

Defined in: [packages/query-db-collection/src/query.ts:107](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L107)
Defined in: [packages/query-db-collection/src/query.ts:136](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L136)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: QueryCollectionUtils

# Interface: QueryCollectionUtils\<TItem, TKey, TInsertInput, TError\>

Defined in: [packages/query-db-collection/src/query.ts:154](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L154)
Defined in: [packages/query-db-collection/src/query.ts:183](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L183)

Utility methods available on Query Collections for direct writes and manual operations.
Direct writes bypass the normal query/mutation flow and write directly to the synced data store.
Expand Down Expand Up @@ -54,7 +54,7 @@ The type of errors that can occur during queries
clearError: () => Promise<void>;
```

Defined in: [packages/query-db-collection/src/query.ts:199](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L199)
Defined in: [packages/query-db-collection/src/query.ts:228](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L228)

Clear the error state and trigger a refetch of the query

Expand All @@ -76,7 +76,7 @@ Error if the refetch fails
dataUpdatedAt: number;
```

Defined in: [packages/query-db-collection/src/query.ts:190](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L190)
Defined in: [packages/query-db-collection/src/query.ts:219](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L219)

Get timestamp of last successful data update (in milliseconds)

Expand All @@ -88,7 +88,7 @@ Get timestamp of last successful data update (in milliseconds)
errorCount: number;
```

Defined in: [packages/query-db-collection/src/query.ts:182](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L182)
Defined in: [packages/query-db-collection/src/query.ts:211](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L211)

Get the number of consecutive sync failures.
Incremented only when query fails completely (not per retry attempt); reset on success.
Expand All @@ -101,7 +101,7 @@ Incremented only when query fails completely (not per retry attempt); reset on s
fetchStatus: "idle" | "fetching" | "paused";
```

Defined in: [packages/query-db-collection/src/query.ts:192](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L192)
Defined in: [packages/query-db-collection/src/query.ts:221](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L221)

Get current fetch status

Expand All @@ -113,7 +113,7 @@ Get current fetch status
isError: boolean;
```

Defined in: [packages/query-db-collection/src/query.ts:177](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L177)
Defined in: [packages/query-db-collection/src/query.ts:206](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L206)

Check if the collection is in an error state

Expand All @@ -125,7 +125,7 @@ Check if the collection is in an error state
isFetching: boolean;
```

Defined in: [packages/query-db-collection/src/query.ts:184](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L184)
Defined in: [packages/query-db-collection/src/query.ts:213](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L213)

Check if query is currently fetching (initial or background)

Expand All @@ -137,7 +137,7 @@ Check if query is currently fetching (initial or background)
isLoading: boolean;
```

Defined in: [packages/query-db-collection/src/query.ts:188](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L188)
Defined in: [packages/query-db-collection/src/query.ts:217](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L217)

Check if query is loading for the first time (no data yet)

Expand All @@ -149,7 +149,7 @@ Check if query is loading for the first time (no data yet)
isRefetching: boolean;
```

Defined in: [packages/query-db-collection/src/query.ts:186](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L186)
Defined in: [packages/query-db-collection/src/query.ts:215](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L215)

Check if query is refetching in background (not initial fetch)

Expand All @@ -161,7 +161,7 @@ Check if query is refetching in background (not initial fetch)
lastError: TError | undefined;
```

Defined in: [packages/query-db-collection/src/query.ts:175](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L175)
Defined in: [packages/query-db-collection/src/query.ts:204](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L204)

Get the last error encountered by the query (if any); reset on success

Expand All @@ -173,7 +173,7 @@ Get the last error encountered by the query (if any); reset on success
refetch: RefetchFn;
```

Defined in: [packages/query-db-collection/src/query.ts:161](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L161)
Defined in: [packages/query-db-collection/src/query.ts:190](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L190)

Manually trigger a refetch of the query

Expand All @@ -185,7 +185,7 @@ Manually trigger a refetch of the query
writeBatch: (callback) => void;
```

Defined in: [packages/query-db-collection/src/query.ts:171](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L171)
Defined in: [packages/query-db-collection/src/query.ts:200](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L200)

Execute multiple write operations as a single atomic batch to the synced data store

Expand All @@ -207,7 +207,7 @@ Execute multiple write operations as a single atomic batch to the synced data st
writeDelete: (keys) => void;
```

Defined in: [packages/query-db-collection/src/query.ts:167](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L167)
Defined in: [packages/query-db-collection/src/query.ts:196](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L196)

Delete one or more items directly from the synced data store without triggering a query refetch or optimistic update

Expand All @@ -229,7 +229,7 @@ Delete one or more items directly from the synced data store without triggering
writeInsert: (data) => void;
```

Defined in: [packages/query-db-collection/src/query.ts:163](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L163)
Defined in: [packages/query-db-collection/src/query.ts:192](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L192)

Insert one or more items directly into the synced data store without triggering a query refetch or optimistic update

Expand All @@ -251,7 +251,7 @@ Insert one or more items directly into the synced data store without triggering
writeUpdate: (updates) => void;
```

Defined in: [packages/query-db-collection/src/query.ts:165](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L165)
Defined in: [packages/query-db-collection/src/query.ts:194](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L194)

Update one or more items directly in the synced data store without triggering a query refetch or optimistic update

Expand All @@ -273,7 +273,7 @@ Update one or more items directly in the synced data store without triggering a
writeUpsert: (data) => void;
```

Defined in: [packages/query-db-collection/src/query.ts:169](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L169)
Defined in: [packages/query-db-collection/src/query.ts:198](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L198)

Insert or update one or more items directly in the synced data store without triggering a query refetch or optimistic update

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: QueryCollectionMeta
title: QueryCollectionMeta
---

# Type Alias: QueryCollectionMeta

```ts
type QueryCollectionMeta = Record<string, unknown> & object;
```

Defined in: [packages/query-db-collection/src/query.ts:50](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L50)

Base type for Query Collection meta properties.
Users can extend this type when augmenting the @tanstack/query-core module
to add their own custom properties while preserving loadSubsetOptions.

## Type Declaration

### loadSubsetOptions

```ts
loadSubsetOptions: LoadSubsetOptions;
```

## Example

```typescript
declare module "@tanstack/query-core" {
interface Register {
queryMeta: QueryCollectionMeta & {
myCustomProperty: string
}
}
}
```