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