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

DbClient.md

635 lines11.7 KB

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