Open History to see the last commit
1---
2id: VirtualRowProps
3title: VirtualRowProps
4---
5
6Defined in: [packages/db/src/virtual-props.ts:57](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L57)
7
8Virtual properties available on every row in TanStack DB collections.
9
10These properties are:
11- Computed (not stored in the data model)
12- Read-only (cannot be mutated directly)
13- Available in queries (WHERE, ORDER BY, SELECT)
14- Included when spreading rows (`...user`)
15
16## Examples
17
18```typescript
19// Accessing virtual properties on a row
20const user = collection.get('user-1')
21if (user.$synced) {
22 console.log('No pending local optimistic writes for this row')
23}
24if (user.$origin === 'local') {
25 console.log('Created/modified locally')
26}
27```
28
29```typescript
30// Using virtual properties in queries
31const ordersWithoutLocalWrites = createLiveQueryCollection({
32 query: (q) => q
33 .from({ order: orders })
34 .where(({ order }) => eq(order.$synced, true))
35})
36```
37
38## Type Parameters
39
40### TKey
41
42`TKey` *extends* `string` \| `number` = `string` \| `number`
43
44The type of the row's key (string or number)
45
46## Properties
47
48### $collectionId
49
50```ts
51readonly $collectionId: string;
52```
53
54Defined in: [packages/db/src/virtual-props.ts:101](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L101)
55
56The ID of the source collection this row originated from.
57
58In joins, this can help identify which collection each row came from.
59For live query collections, this is the ID of the upstream collection.
60
61***
62
63### $key
64
65```ts
66readonly $key: TKey;
67```
68
69Defined in: [packages/db/src/virtual-props.ts:93](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L93)
70
71The row's key (primary identifier).
72
73This is the same value returned by `collection.config.getKey(row)`.
74Useful when you need the key in projections or computations.
75
76***
77
78### $origin
79
80```ts
81readonly $origin: VirtualOrigin;
82```
83
84Defined in: [packages/db/src/virtual-props.ts:85](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L85)
85
86Origin of the last confirmed change to this row, from the current client's perspective.
87
88- `'local'`: The change originated from this client
89- `'remote'`: The change was received via sync
90
91For local-only collections, this is always `'local'`.
92For live query collections, this is passed through from the source collection.
93
94***
95
96### $synced
97
98```ts
99readonly $synced: boolean;
100```
101
102Defined in: [packages/db/src/virtual-props.ts:74](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L74)
103
104Whether this row currently has no pending local optimistic writes.
105
106- `true`: No pending local optimistic mutation currently affects this row
107- `false`: One or more pending local optimistic mutations currently affect this row
108
109This is local mutation status. It does not prove that a backend has uploaded,
110confirmed, or read back the row. If you need backend-confirmed status, keep
111your mutation function pending until that backend observation has happened,
112or expose adapter-specific status.
113
114For local-only collections (no sync), this is always `true`.
115For live query collections, this is passed through from the source collection.