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