Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

QueryCollectionUtils.md

240 lines4.6 KB

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

Defined in: packages/query-db-collection/src/query.ts:153

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.

Extends

  • UtilsRecord

Type Parameters

TItem

TItem extends object = Record<string, unknown>

The type of items stored in the collection

TKey

TKey extends string | number = string | number

The type of the item keys

TInsertInput

TInsertInput extends object = TItem

The type accepted for insert operations

TError

TError = unknown

The type of errors that can occur during queries

Indexable

[key: string]: Fn

Properties

clearError()

clearError: () => Promise<void>;

Defined in: packages/query-db-collection/src/query.ts:185

Clear the error state and trigger a refetch of the query

Returns

Promise<void>

Promise that resolves when the refetch completes successfully

Throws

Error if the refetch fails


errorCount()

errorCount: () => number;

Defined in: packages/query-db-collection/src/query.ts:179

Get the number of consecutive sync failures. Incremented only when query fails completely (not per retry attempt); reset on success.

Returns

number


isError()

isError: () => boolean;

Defined in: packages/query-db-collection/src/query.ts:174

Check if the collection is in an error state

Returns

boolean


lastError()

lastError: () => TError | undefined;

Defined in: packages/query-db-collection/src/query.ts:172

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

Returns

TError | undefined


refetch

refetch: RefetchFn;

Defined in: packages/query-db-collection/src/query.ts:160

Manually trigger a refetch of the query


writeBatch()

writeBatch: (callback) => void;

Defined in: packages/query-db-collection/src/query.ts:170

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

Parameters

callback

() => void

Returns

void


writeDelete()

writeDelete: (keys) => void;

Defined in: packages/query-db-collection/src/query.ts:166

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

Parameters

keys

TKey | TKey[]

Returns

void


writeInsert()

writeInsert: (data) => void;

Defined in: packages/query-db-collection/src/query.ts:162

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

Parameters

data

TInsertInput | TInsertInput[]

Returns

void


writeUpdate()

writeUpdate: (updates) => void;

Defined in: packages/query-db-collection/src/query.ts:164

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

Parameters

updates

Partial<TItem> | Partial<TItem>[]

Returns

void


writeUpsert()

writeUpsert: (data) => void;

Defined in: packages/query-db-collection/src/query.ts:168

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

Parameters

data

Partial<TItem> | Partial<TItem>[]

Returns

void