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

LiveQuerySnapshot.md

150 lines3.5 KB

1---
2id: LiveQuerySnapshot
3title: LiveQuerySnapshot
4---
5​
6Defined in: [packages/db/src/live-query-observer.ts:19](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L19)
7​
8The canonical, adapter-agnostic view of a live query at a point in time.
9​
10`getSnapshot()` returns a stable object identity that only changes when the
11query changes, so `useSyncExternalStore`-style consumers can compare by
12reference. Each snapshot owns a captured view of `state`/`data`, so reading
13an older snapshot cannot expose rows from a later revision.
14​
15## Type Parameters
16​
17### T
18​
19`T` *extends* `object`
20​
21### TKey
22​
23`TKey` *extends* `string` \| `number`
24​
25## Properties
26​
27### collection
28​
29```ts
30collection:
31 | Collection<T, TKey, any, StandardSchemaV1<unknown, unknown>, T>
32 | undefined;
33```
34​
35Defined in: [packages/db/src/live-query-observer.ts:28](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L28)
36​
37The underlying collection, or `undefined` when disabled.
38​
39***
40​
41### data
42​
43```ts
44data: T | readonly T[] | undefined;
45```
46​
47Defined in: [packages/db/src/live-query-observer.ts:26](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L26)
48​
49Ordered results (single row for `findOne`), or `undefined` when disabled.
50​
51***
52​
53### isCleanedUp
54​
55```ts
56isCleanedUp: boolean;
57```
58​
59Defined in: [packages/db/src/live-query-observer.ts:45](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L45)
60​
61***
62​
63### isEnabled
64​
65```ts
66isEnabled: boolean;
67```
68​
69Defined in: [packages/db/src/live-query-observer.ts:46](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L46)
70​
71***
72​
73### isError
74​
75```ts
76isError: boolean;
77```
78​
79Defined in: [packages/db/src/live-query-observer.ts:44](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L44)
80​
81***
82​
83### isIdle
84​
85```ts
86isIdle: boolean;
87```
88​
89Defined in: [packages/db/src/live-query-observer.ts:43](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L43)
90​
91***
92​
93### isLoading
94​
95```ts
96isLoading: boolean;
97```
98​
99Defined in: [packages/db/src/live-query-observer.ts:41](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L41)
100​
101***
102​
103### isReady
104​
105```ts
106isReady: boolean;
107```
108​
109Defined in: [packages/db/src/live-query-observer.ts:42](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L42)
110​
111***
112​
113### layoutRevision
114​
115```ts
116layoutRevision: number;
117```
118​
119Defined in: [packages/db/src/live-query-observer.ts:39](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L39)
120​
121Monotonic counter bumped whenever the visible layout (the ordered key
122sequence) changes — membership, ordering, or an order-only move. Lets
123consumers detect a reorder that changed no row value (which `data`/`state`
124identity alone can't express once row values are structurally shared).
125​
126It is NOT in lockstep with snapshot identity: a value-only update produces a
127new snapshot while `layoutRevision` stays put. A `layoutRevision` change
128always accompanies a new snapshot, but not vice versa.
129​
130***
131​
132### state
133​
134```ts
135state: ReadonlyMap<TKey, T> | undefined;
136```
137​
138Defined in: [packages/db/src/live-query-observer.ts:24](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L24)
139​
140Keyed results, or `undefined` for a disabled query.
141​
142***
143​
144### status
145​
146```ts
147status: CollectionStatus | "disabled";
148```
149​
150Defined in: [packages/db/src/live-query-observer.ts:40](https://github.com/TanStack/db/blob/main/packages/db/src/live-query-observer.ts#L40)