Open History to see the last commit
1---
2id: DbClient
3title: DbClient
4---
5
6Defined in: [packages/db/src/client.ts:348](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L348)
7
8## Constructors
9
10### Constructor
11
12```ts
13new DbClient(options): DbClient;
14```
15
16Defined in: [packages/db/src/client.ts:375](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L375)
17
18#### Parameters
19
20##### options
21
22[`DbClientOptions`](../type-aliases/DbClientOptions.md) = `{}`
23
24#### Returns
25
26`DbClient`
27
28## Accessors
29
30### activeTransaction
31
32#### Get Signature
33
34```ts
35get activeTransaction():
36 | Transaction<Record<string, unknown>>
37 | undefined;
38```
39
40Defined in: [packages/db/src/client.ts:393](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L393)
41
42##### Returns
43
44 \| [`Transaction`](../interfaces/Transaction.md)\<`Record`\<`string`, `unknown`\>\>
45 \| `undefined`
46
47## Methods
48
49### \_assertLiveQuerySources()
50
51```ts
52_assertLiveQuerySources(queryHash, sources): void;
53```
54
55Defined in: [packages/db/src/client.ts:831](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L831)
56
57**`Internal`**
58
59Reject a local stream whose hash already names different sources.
60
61#### Parameters
62
63##### queryHash
64
65`string`
66
67##### sources
68
69readonly `AnyCollection`[]
70
71#### Returns
72
73`void`
74
75***
76
77### \_bindLiveQueryObserver()
78
79```ts
80_bindLiveQueryObserver<T, TKey>(
81 collection,
82 queryHash,
83 suspendUntilReady,
84host): LiveQueryObserverClient<T, TKey>;
85```
86
87Defined in: [packages/db/src/client.ts:729](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L729)
88
89**`Internal`**
90
91Supply transport behavior without coupling ordinary observers to SSR.
92
93#### Type Parameters
94
95##### T
96
97`T` *extends* `object`
98
99##### TKey
100
101`TKey` *extends* `string` \| `number`
102
103#### Parameters
104
105##### collection
106
107[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `any`, `StandardSchemaV1`\<`unknown`, `unknown`\>, `T`\> | `null`
108
109##### queryHash
110
111`string` | `undefined`
112
113##### suspendUntilReady
114
115`boolean`
116
117##### host
118
119`LiveQueryObserverClientHost`\<`T`, `TKey`\>
120
121#### Returns
122
123`LiveQueryObserverClient`\<`T`, `TKey`\>
124
125***
126
127### \_captureServerQuery()
128
129```ts
130_captureServerQuery(
131 queryHash,
132 snapshot,
133 sources?): void;
134```
135
136Defined in: [packages/db/src/client.ts:861](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L861)
137
138**`Internal`**
139
140Capture the first server view without starting acquisition.
141
142#### Parameters
143
144##### queryHash
145
146`string`
147
148##### snapshot
149
150[`DehydratedLiveQueryResult`](../type-aliases/DehydratedLiveQueryResult.md)
151
152##### sources?
153
154readonly `AnyCollection`[]
155
156#### Returns
157
158`void`
159
160***
161
162### \_consumeLiveQueryResult()
163
164```ts
165_consumeLiveQueryResult(queryHash, dehydratedAt): void;
166```
167
168Defined in: [packages/db/src/client.ts:853](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L853)
169
170**`Internal`**
171
172#### Parameters
173
174##### queryHash
175
176`string`
177
178##### dehydratedAt
179
180`number`
181
182#### Returns
183
184`void`
185
186***
187
188### \_failPendingLiveQueries()
189
190```ts
191_failPendingLiveQueries(error): void;
192```
193
194Defined in: [packages/db/src/client.ts:939](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L939)
195
196**`Internal`**
197
198#### Parameters
199
200##### error
201
202`unknown`
203
204#### Returns
205
206`void`
207
208***
209
210### \_getLiveQuery()
211
212```ts
213_getLiveQuery(queryHash, forServerSnapshot): DbClientLiveQuery | undefined;
214```
215
216Defined in: [packages/db/src/client.ts:820](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L820)
217
218**`Internal`**
219
220#### Parameters
221
222##### queryHash
223
224`string`
225
226##### forServerSnapshot
227
228`boolean` = `false`
229
230#### Returns
231
232[`DbClientLiveQuery`](../type-aliases/DbClientLiveQuery.md) \| `undefined`
233
234***
235
236### \_hasSsrCollectionSnapshot()
237
238```ts
239_hasSsrCollectionSnapshot(collection): boolean;
240```
241
242Defined in: [packages/db/src/client.ts:745](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L745)
243
244**`Internal`**
245
246Normalized source transport carries rows, not readiness.
247
248#### Parameters
249
250##### collection
251
252`AnyCollection`
253
254#### Returns
255
256`boolean`
257
258***
259
260### \_isSsrServerCleanupEnabled()
261
262```ts
263_isSsrServerCleanupEnabled(): boolean;
264```
265
266Defined in: [packages/db/src/client.ts:815](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L815)
267
268**`Internal`**
269
270#### Returns
271
272`boolean`
273
274***
275
276### \_isSsrStreamingEnabled()
277
278```ts
279_isSsrStreamingEnabled(): boolean;
280```
281
282Defined in: [packages/db/src/client.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L805)
283
284**`Internal`**
285
286#### Returns
287
288`boolean`
289
290***
291
292### \_materializeCollectionForRender()
293
294```ts
295_materializeCollectionForRender<T, TKey, TSchema, TUtils>(options): Collection<T, TKey, TUtils, TSchema, [TSchema] extends [never] ? T : InferSchemaInput<TSchema>>;
296```
297
298Defined in: [packages/db/src/client.ts:541](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L541)
299
300**`Internal`**
301
302#### Type Parameters
303
304##### T
305
306`T` *extends* `object`
307
308##### TKey
309
310`TKey` *extends* `string` \| `number`
311
312##### TSchema
313
314`TSchema` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
315
316##### TUtils
317
318`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
319
320#### Parameters
321
322##### options
323
324[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `TSchema`, `TUtils`\>
325
326#### Returns
327
328[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `TSchema`, \[`TSchema`\] *extends* \[`never`\] ? `T` : [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`TSchema`\>\>
329
330***
331
332### \_registerLiveQuery()
333
334```ts
335_registerLiveQuery(
336 queryHash,
337 promise,
338sources?): Promise<void>;
339```
340
341Defined in: [packages/db/src/client.ts:894](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L894)
342
343**`Internal`**
344
345#### Parameters
346
347##### queryHash
348
349`string`
350
351##### promise
352
353`Promise`\<[`DehydratedLiveQueryResult`](../type-aliases/DehydratedLiveQueryResult.md)\<`object`, `string` \| `number`\>\>
354
355##### sources?
356
357readonly `AnyCollection`[]
358
359#### Returns
360
361`Promise`\<`void`\>
362
363***
364
365### \_registerLiveQueryResource()
366
367```ts
368_registerLiveQueryResource(owner, cleanup): () => void;
369```
370
371Defined in: [packages/db/src/client.ts:926](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L926)
372
373**`Internal`**
374
375#### Parameters
376
377##### owner
378
379`object`
380
381##### cleanup
382
383() => `Promise`\<`void`\>
384
385#### Returns
386
387```ts
388(): void;
389```
390
391##### Returns
392
393`void`
394
395***
396
397### \_setSsrServerCleanupEnabled()
398
399```ts
400_setSsrServerCleanupEnabled(enabled): void;
401```
402
403Defined in: [packages/db/src/client.ts:810](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L810)
404
405**`Internal`**
406
407#### Parameters
408
409##### enabled
410
411`boolean`
412
413#### Returns
414
415`void`
416
417***
418
419### \_setSsrStreamingEnabled()
420
421```ts
422_setSsrStreamingEnabled(enabled): void;
423```
424
425Defined in: [packages/db/src/client.ts:759](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L759)
426
427**`Internal`**
428
429#### Parameters
430
431##### enabled
432
433`boolean`
434
435#### Returns
436
437`void`
438
439***
440
441### \_waitForSsrLiveQuery()
442
443```ts
444_waitForSsrLiveQuery(queryHash, forHydration): Promise<void> | undefined;
445```
446
447Defined in: [packages/db/src/client.ts:775](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L775)
448
449**`Internal`**
450
451Wait for transport without claiming or starting a local source.
452
453#### Parameters
454
455##### queryHash
456
457`string`
458
459##### forHydration
460
461`boolean` = `false`
462
463#### Returns
464
465`Promise`\<`void`\> \| `undefined`
466
467***
468
469### applyCollectionChunk()
470
471```ts
472applyCollectionChunk(chunk): void;
473```
474
475Defined in: [packages/db/src/client.ts:719](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L719)
476
477#### Parameters
478
479##### chunk
480
481[`DehydratedCollectionChunk`](../type-aliases/DehydratedCollectionChunk.md)
482
483#### Returns
484
485`void`
486
487***
488
489### cleanup()
490
491```ts
492cleanup(): Promise<void>;
493```
494
495Defined in: [packages/db/src/client.ts:947](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L947)
496
497#### Returns
498
499`Promise`\<`void`\>
500
501***
502
503### collection()
504
505#### Call Signature
506
507```ts
508collection<T, TKey, TUtils>(options, materializeOptions?): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & NonSingleResult;
509```
510
511Defined in: [packages/db/src/client.ts:497](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L497)
512
513##### Type Parameters
514
515###### T
516
517`T` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
518
519###### TKey
520
521`TKey` *extends* `string` \| `number`
522
523###### TUtils
524
525`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
526
527##### Parameters
528
529###### options
530
531[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `T`, `TUtils`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
532
533###### materializeOptions?
534
535[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<[`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\>
536
537##### Returns
538
539[`Collection`](../interfaces/Collection.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `TUtils`, `T`, [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
540
541#### Call Signature
542
543```ts
544collection<T, TKey, TUtils>(options, materializeOptions?): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult;
545```
546
547Defined in: [packages/db/src/client.ts:507](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L507)
548
549##### Type Parameters
550
551###### T
552
553`T` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
554
555###### TKey
556
557`TKey` *extends* `string` \| `number`
558
559###### TUtils
560
561`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
562
563##### Parameters
564
565###### options
566
567[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `T`, `TUtils`\> & [`SingleResult`](../type-aliases/SingleResult.md)
568
569###### materializeOptions?
570
571[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<[`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\>
572
573##### Returns
574
575[`Collection`](../interfaces/Collection.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `TUtils`, `T`, [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\> & [`SingleResult`](../type-aliases/SingleResult.md)
576
577#### Call Signature
578
579```ts
580collection<T, TKey, TUtils>(options, materializeOptions?): Collection<T, TKey, TUtils, never, T> & NonSingleResult;
581```
582
583Defined in: [packages/db/src/client.ts:517](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L517)
584
585##### Type Parameters
586
587###### T
588
589`T` *extends* `object`
590
591###### TKey
592
593`TKey` *extends* `string` \| `number` = `string` \| `number`
594
595###### TUtils
596
597`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md) = [`UtilsRecord`](../type-aliases/UtilsRecord.md)
598
599##### Parameters
600
601###### options
602
603[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `never`, `TUtils`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
604
605###### materializeOptions?
606
607[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<`T`\>
608
609##### Returns
610
611[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `never`, `T`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
612
613#### Call Signature
614
615```ts
616collection<T, TKey, TUtils>(options, materializeOptions?): Collection<T, TKey, TUtils, never, T> & SingleResult;
617```
618
619Defined in: [packages/db/src/client.ts:525](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L525)
620
621##### Type Parameters
622
623###### T
624
625`T` *extends* `object`
626
627###### TKey
628
629`TKey` *extends* `string` \| `number` = `string` \| `number`
630
631###### TUtils
632
633`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md) = [`UtilsRecord`](../type-aliases/UtilsRecord.md)
634
635##### Parameters
636
637###### options
638
639[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `never`, `TUtils`\> & [`SingleResult`](../type-aliases/SingleResult.md)
640
641###### materializeOptions?
642
643[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<`T`\>
644
645##### Returns
646
647[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `never`, `T`\> & [`SingleResult`](../type-aliases/SingleResult.md)
648
649***
650
651### createTransaction()
652
653```ts
654createTransaction<T>(config): Transaction<T>;
655```
656
657Defined in: [packages/db/src/client.ts:397](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L397)
658
659#### Type Parameters
660
661##### T
662
663`T` *extends* `object` = `Record`\<`string`, `unknown`\>
664
665#### Parameters
666
667##### config
668
669[`TransactionConfig`](../interfaces/TransactionConfig.md)\<`T`\>
670
671#### Returns
672
673[`Transaction`](../interfaces/Transaction.md)\<`T`\>
674
675***
676
677### dehydrate()
678
679```ts
680dehydrate(options): DehydratedDbState;
681```
682
683Defined in: [packages/db/src/client.ts:632](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L632)
684
685#### Parameters
686
687##### options
688
689[`DehydrateDbClientOptions`](../type-aliases/DehydrateDbClientOptions.md) = `{}`
690
691#### Returns
692
693[`DehydratedDbState`](../type-aliases/DehydratedDbState.md)
694
695***
696
697### getDependency()
698
699```ts
700getDependency<T>(key): T | undefined;
701```
702
703Defined in: [packages/db/src/client.ts:377](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L377)
704
705#### Type Parameters
706
707##### T
708
709`T`
710
711#### Parameters
712
713##### key
714
715`string`
716
717#### Returns
718
719`T` \| `undefined`
720
721***
722
723### hydrate()
724
725```ts
726hydrate(state): void;
727```
728
729Defined in: [packages/db/src/client.ts:700](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L700)
730
731#### Parameters
732
733##### state
734
735[`DehydratedDbState`](../type-aliases/DehydratedDbState.md)
736
737#### Returns
738
739`void`
740
741***
742
743### preloadLiveQuery()
744
745```ts
746preloadLiveQuery(options): Promise<void>;
747```
748
749Defined in: [packages/db/src/client.ts:403](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L403)
750
751#### Parameters
752
753##### options
754
755[`LiveQueryOptions`](../type-aliases/LiveQueryOptions.md)
756
757#### Returns
758
759`Promise`\<`void`\>
760
761***
762
763### requireDependency()
764
765```ts
766requireDependency<T>(key): T;
767```
768
769Defined in: [packages/db/src/client.ts:381](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L381)
770
771#### Type Parameters
772
773##### T
774
775`T`
776
777#### Parameters
778
779##### key
780
781`string`
782
783#### Returns
784
785`T`
786
787***
788
789### subscribe()
790
791```ts
792subscribe(listener): () => void;
793```
794
795Defined in: [packages/db/src/client.ts:723](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L723)
796
797#### Parameters
798
799##### listener
800
801(`event`) => `void`
802
803#### Returns
804
805```ts
806(): void;
807```
808
809##### Returns
810
811`void`