Open History to see the last commit
1---
2id: DbClient
3title: DbClient
4---
5
6Defined in: [packages/db/src/client.ts:337](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L337)
7
8## Constructors
9
10### Constructor
11
12```ts
13new DbClient(options): DbClient;
14```
15
16Defined in: [packages/db/src/client.ts:356](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L356)
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:374](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L374)
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:721](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L721)
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### \_consumeLiveQueryResult()
78
79```ts
80_consumeLiveQueryResult(queryHash, dehydratedAt): void;
81```
82
83Defined in: [packages/db/src/client.ts:743](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L743)
84
85**`Internal`**
86
87#### Parameters
88
89##### queryHash
90
91`string`
92
93##### dehydratedAt
94
95`number`
96
97#### Returns
98
99`void`
100
101***
102
103### \_failPendingLiveQueries()
104
105```ts
106_failPendingLiveQueries(error): void;
107```
108
109Defined in: [packages/db/src/client.ts:789](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L789)
110
111**`Internal`**
112
113#### Parameters
114
115##### error
116
117`unknown`
118
119#### Returns
120
121`void`
122
123***
124
125### \_getLiveQuery()
126
127```ts
128_getLiveQuery(queryHash): DbClientLiveQuery | undefined;
129```
130
131Defined in: [packages/db/src/client.ts:716](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L716)
132
133**`Internal`**
134
135#### Parameters
136
137##### queryHash
138
139`string`
140
141#### Returns
142
143[`DbClientLiveQuery`](../type-aliases/DbClientLiveQuery.md) \| `undefined`
144
145***
146
147### \_isSsrServerCleanupEnabled()
148
149```ts
150_isSsrServerCleanupEnabled(): boolean;
151```
152
153Defined in: [packages/db/src/client.ts:711](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L711)
154
155**`Internal`**
156
157#### Returns
158
159`boolean`
160
161***
162
163### \_isSsrStreamingEnabled()
164
165```ts
166_isSsrStreamingEnabled(): boolean;
167```
168
169Defined in: [packages/db/src/client.ts:701](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L701)
170
171**`Internal`**
172
173#### Returns
174
175`boolean`
176
177***
178
179### \_materializeCollectionForRender()
180
181```ts
182_materializeCollectionForRender<T, TKey, TSchema, TUtils>(options): Collection<T, TKey, TUtils, TSchema, [TSchema] extends [never] ? T : InferSchemaInput<TSchema>>;
183```
184
185Defined in: [packages/db/src/client.ts:517](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L517)
186
187**`Internal`**
188
189#### Type Parameters
190
191##### T
192
193`T` *extends* `object`
194
195##### TKey
196
197`TKey` *extends* `string` \| `number`
198
199##### TSchema
200
201`TSchema` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
202
203##### TUtils
204
205`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
206
207#### Parameters
208
209##### options
210
211[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `TSchema`, `TUtils`\>
212
213#### Returns
214
215[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `TSchema`, \[`TSchema`\] *extends* \[`never`\] ? `T` : [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`TSchema`\>\>
216
217***
218
219### \_registerLiveQuery()
220
221```ts
222_registerLiveQuery(
223 queryHash,
224 promise,
225sources?): Promise<void>;
226```
227
228Defined in: [packages/db/src/client.ts:751](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L751)
229
230**`Internal`**
231
232#### Parameters
233
234##### queryHash
235
236`string`
237
238##### promise
239
240`Promise`\<[`DehydratedLiveQueryResult`](../type-aliases/DehydratedLiveQueryResult.md)\<`object`, `string` \| `number`\>\>
241
242##### sources?
243
244readonly `AnyCollection`[]
245
246#### Returns
247
248`Promise`\<`void`\>
249
250***
251
252### \_registerLiveQueryResource()
253
254```ts
255_registerLiveQueryResource(owner, cleanup): () => void;
256```
257
258Defined in: [packages/db/src/client.ts:776](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L776)
259
260**`Internal`**
261
262#### Parameters
263
264##### owner
265
266`object`
267
268##### cleanup
269
270() => `Promise`\<`void`\>
271
272#### Returns
273
274```ts
275(): void;
276```
277
278##### Returns
279
280`void`
281
282***
283
284### \_setSsrServerCleanupEnabled()
285
286```ts
287_setSsrServerCleanupEnabled(enabled): void;
288```
289
290Defined in: [packages/db/src/client.ts:706](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L706)
291
292**`Internal`**
293
294#### Parameters
295
296##### enabled
297
298`boolean`
299
300#### Returns
301
302`void`
303
304***
305
306### \_setSsrStreamingEnabled()
307
308```ts
309_setSsrStreamingEnabled(enabled): void;
310```
311
312Defined in: [packages/db/src/client.ts:696](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L696)
313
314**`Internal`**
315
316#### Parameters
317
318##### enabled
319
320`boolean`
321
322#### Returns
323
324`void`
325
326***
327
328### applyCollectionChunk()
329
330```ts
331applyCollectionChunk(chunk): void;
332```
333
334Defined in: [packages/db/src/client.ts:686](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L686)
335
336#### Parameters
337
338##### chunk
339
340[`DehydratedCollectionChunk`](../type-aliases/DehydratedCollectionChunk.md)
341
342#### Returns
343
344`void`
345
346***
347
348### cleanup()
349
350```ts
351cleanup(): Promise<void>;
352```
353
354Defined in: [packages/db/src/client.ts:796](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L796)
355
356#### Returns
357
358`Promise`\<`void`\>
359
360***
361
362### collection()
363
364#### Call Signature
365
366```ts
367collection<T, TKey, TUtils>(options, materializeOptions?): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & NonSingleResult;
368```
369
370Defined in: [packages/db/src/client.ts:473](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L473)
371
372##### Type Parameters
373
374###### T
375
376`T` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
377
378###### TKey
379
380`TKey` *extends* `string` \| `number`
381
382###### TUtils
383
384`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
385
386##### Parameters
387
388###### options
389
390[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `T`, `TUtils`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
391
392###### materializeOptions?
393
394[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<[`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\>
395
396##### Returns
397
398[`Collection`](../interfaces/Collection.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `TUtils`, `T`, [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
399
400#### Call Signature
401
402```ts
403collection<T, TKey, TUtils>(options, materializeOptions?): Collection<InferSchemaOutput<T>, TKey, TUtils, T, InferSchemaInput<T>> & SingleResult;
404```
405
406Defined in: [packages/db/src/client.ts:483](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L483)
407
408##### Type Parameters
409
410###### T
411
412`T` *extends* `StandardSchemaV1`\<`unknown`, `unknown`\>
413
414###### TKey
415
416`TKey` *extends* `string` \| `number`
417
418###### TUtils
419
420`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md)
421
422##### Parameters
423
424###### options
425
426[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `T`, `TUtils`\> & [`SingleResult`](../type-aliases/SingleResult.md)
427
428###### materializeOptions?
429
430[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<[`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\>
431
432##### Returns
433
434[`Collection`](../interfaces/Collection.md)\<[`InferSchemaOutput`](../type-aliases/InferSchemaOutput.md)\<`T`\>, `TKey`, `TUtils`, `T`, [`InferSchemaInput`](../type-aliases/InferSchemaInput.md)\<`T`\>\> & [`SingleResult`](../type-aliases/SingleResult.md)
435
436#### Call Signature
437
438```ts
439collection<T, TKey, TUtils>(options, materializeOptions?): Collection<T, TKey, TUtils, never, T> & NonSingleResult;
440```
441
442Defined in: [packages/db/src/client.ts:493](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L493)
443
444##### Type Parameters
445
446###### T
447
448`T` *extends* `object`
449
450###### TKey
451
452`TKey` *extends* `string` \| `number` = `string` \| `number`
453
454###### TUtils
455
456`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md) = [`UtilsRecord`](../type-aliases/UtilsRecord.md)
457
458##### Parameters
459
460###### options
461
462[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `never`, `TUtils`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
463
464###### materializeOptions?
465
466[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<`T`\>
467
468##### Returns
469
470[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `never`, `T`\> & [`NonSingleResult`](../type-aliases/NonSingleResult.md)
471
472#### Call Signature
473
474```ts
475collection<T, TKey, TUtils>(options, materializeOptions?): Collection<T, TKey, TUtils, never, T> & SingleResult;
476```
477
478Defined in: [packages/db/src/client.ts:501](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L501)
479
480##### Type Parameters
481
482###### T
483
484`T` *extends* `object`
485
486###### TKey
487
488`TKey` *extends* `string` \| `number` = `string` \| `number`
489
490###### TUtils
491
492`TUtils` *extends* [`UtilsRecord`](../type-aliases/UtilsRecord.md) = [`UtilsRecord`](../type-aliases/UtilsRecord.md)
493
494##### Parameters
495
496###### options
497
498[`CollectionOptions`](../type-aliases/CollectionOptions.md)\<`T`, `TKey`, `never`, `TUtils`\> & [`SingleResult`](../type-aliases/SingleResult.md)
499
500###### materializeOptions?
501
502[`CollectionMaterializeOptions`](../type-aliases/CollectionMaterializeOptions.md)\<`T`\>
503
504##### Returns
505
506[`Collection`](../interfaces/Collection.md)\<`T`, `TKey`, `TUtils`, `never`, `T`\> & [`SingleResult`](../type-aliases/SingleResult.md)
507
508***
509
510### createTransaction()
511
512```ts
513createTransaction<T>(config): Transaction<T>;
514```
515
516Defined in: [packages/db/src/client.ts:378](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L378)
517
518#### Type Parameters
519
520##### T
521
522`T` *extends* `object` = `Record`\<`string`, `unknown`\>
523
524#### Parameters
525
526##### config
527
528[`TransactionConfig`](../interfaces/TransactionConfig.md)\<`T`\>
529
530#### Returns
531
532[`Transaction`](../interfaces/Transaction.md)\<`T`\>
533
534***
535
536### dehydrate()
537
538```ts
539dehydrate(options): DehydratedDbState;
540```
541
542Defined in: [packages/db/src/client.ts:607](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L607)
543
544#### Parameters
545
546##### options
547
548[`DehydrateDbClientOptions`](../type-aliases/DehydrateDbClientOptions.md) = `{}`
549
550#### Returns
551
552[`DehydratedDbState`](../type-aliases/DehydratedDbState.md)
553
554***
555
556### getDependency()
557
558```ts
559getDependency<T>(key): T | undefined;
560```
561
562Defined in: [packages/db/src/client.ts:358](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L358)
563
564#### Type Parameters
565
566##### T
567
568`T`
569
570#### Parameters
571
572##### key
573
574`string`
575
576#### Returns
577
578`T` \| `undefined`
579
580***
581
582### hydrate()
583
584```ts
585hydrate(state): void;
586```
587
588Defined in: [packages/db/src/client.ts:668](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L668)
589
590#### Parameters
591
592##### state
593
594[`DehydratedDbState`](../type-aliases/DehydratedDbState.md)
595
596#### Returns
597
598`void`
599
600***
601
602### preloadLiveQuery()
603
604```ts
605preloadLiveQuery(options): Promise<void>;
606```
607
608Defined in: [packages/db/src/client.ts:384](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L384)
609
610#### Parameters
611
612##### options
613
614[`LiveQueryOptions`](../type-aliases/LiveQueryOptions.md)
615
616#### Returns
617
618`Promise`\<`void`\>
619
620***
621
622### requireDependency()
623
624```ts
625requireDependency<T>(key): T;
626```
627
628Defined in: [packages/db/src/client.ts:362](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L362)
629
630#### Type Parameters
631
632##### T
633
634`T`
635
636#### Parameters
637
638##### key
639
640`string`
641
642#### Returns
643
644`T`
645
646***
647
648### subscribe()
649
650```ts
651subscribe(listener): () => void;
652```
653
654Defined in: [packages/db/src/client.ts:690](https://github.com/TanStack/db/blob/main/packages/db/src/client.ts#L690)
655
656#### Parameters
657
658##### listener
659
660(`event`) => `void`
661
662#### Returns
663
664```ts
665(): void;
666```
667
668##### Returns
669
670`void`