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

LiveQuerySnapshot.md

191 lines4.5 KB

Defined in: packages/db/src/live-query-observer.ts:23

The canonical, adapter-agnostic view of a live query at a point in time.

getSnapshot() returns a stable object identity that only changes when the query changes, so useSyncExternalStore-style consumers can compare by reference. Each snapshot owns a captured view of state/data, so reading an older snapshot cannot expose rows from a later revision.

Type Parameters

T

T extends object

TKey

TKey extends string | number

Properties

collection

collection: 
  | Collection<T, TKey, any, StandardSchemaV1<unknown, unknown>, T>
  | undefined;

Defined in: packages/db/src/live-query-observer.ts:32

The underlying collection, or undefined when disabled.


data

data: T | readonly T[] | undefined;

Defined in: packages/db/src/live-query-observer.ts:30

Ordered results (single row for findOne), or undefined when disabled.


health

health: HealthNode | undefined;

Defined in: packages/db/src/live-query-observer.ts:64

The health tree for the query and every Collection it depends on, or undefined for a disabled query. After the first ready, a source problem shows here and the data stays.


isCleanedUp

isCleanedUp: boolean;

Defined in: packages/db/src/live-query-observer.ts:52


isCrashed

isCrashed: boolean;

Defined in: packages/db/src/live-query-observer.ts:51

Local storage or an invariant broke. Only a cascade cleanup and a fresh start recover.


isEnabled

isEnabled: boolean;

Defined in: packages/db/src/live-query-observer.ts:53


isIdle

isIdle: boolean;

Defined in: packages/db/src/live-query-observer.ts:47


isLoading

isLoading: boolean;

Defined in: packages/db/src/live-query-observer.ts:45


isLoadingError

isLoadingError: boolean;

Defined in: packages/db/src/live-query-observer.ts:49

The first load failed: there is nothing to show.


isReady

isReady: boolean;

Defined in: packages/db/src/live-query-observer.ts:46


isSyncError

isSyncError: boolean;

Defined in: packages/db/src/live-query-observer.ts:58

The data is shown, and something keeps it from staying current: a sync problem or a failed request somewhere in health.


layoutRevision

layoutRevision: number;

Defined in: packages/db/src/live-query-observer.ts:43

Monotonic counter bumped whenever the visible layout (the ordered key sequence) changes — membership, ordering, or an order-only move. Lets consumers detect a reorder that changed no row value (which data/state identity alone can't express once row values are structurally shared).

It is NOT in lockstep with snapshot identity: a value-only update produces a new snapshot while layoutRevision stays put. A layoutRevision change always accompanies a new snapshot, but not vice versa.


state

state: ReadonlyMap<TKey, T> | undefined;

Defined in: packages/db/src/live-query-observer.ts:28

Keyed results, or undefined for a disabled query.


status

status: CollectionStatus | "disabled";

Defined in: packages/db/src/live-query-observer.ts:44