VirtualRowProps

Interface: VirtualRowProps<TKey>

Defined in: packages/db/src/virtual-props.ts:57

Virtual properties available on every row in TanStack DB collections.

These properties are:

  • Computed (not stored in the data model)
  • Read-only (cannot be mutated directly)
  • Available in queries (WHERE, ORDER BY, SELECT)
  • Included when spreading rows (...user)

Examples

typescript
// Accessing virtual properties on a row
const user = collection.get('user-1')
if (user.$synced) {
  console.log('No pending local optimistic writes for this row')
}
if (user.$origin === 'local') {
  console.log('Created/modified locally')
}
// Accessing virtual properties on a row
const user = collection.get('user-1')
if (user.$synced) {
  console.log('No pending local optimistic writes for this row')
}
if (user.$origin === 'local') {
  console.log('Created/modified locally')
}
typescript
// Using virtual properties in queries
const ordersWithoutLocalWrites = createLiveQueryCollection({
  query: (q) => q
    .from({ order: orders })
    .where(({ order }) => eq(order.$synced, true))
})
// Using virtual properties in queries
const ordersWithoutLocalWrites = createLiveQueryCollection({
  query: (q) => q
    .from({ order: orders })
    .where(({ order }) => eq(order.$synced, true))
})

Type Parameters

TKey

TKey extends string | number = string | number

The type of the row's key (string or number)

Properties

$collectionId

ts
readonly $collectionId: string;
readonly $collectionId: string;

Defined in: packages/db/src/virtual-props.ts:101

The ID of the source collection this row originated from.

In joins, this can help identify which collection each row came from. For live query collections, this is the ID of the upstream collection.


$key

ts
readonly $key: TKey;
readonly $key: TKey;

Defined in: packages/db/src/virtual-props.ts:93

The row's key (primary identifier).

This is the same value returned by collection.config.getKey(row). Useful when you need the key in projections or computations.


$origin

ts
readonly $origin: VirtualOrigin;
readonly $origin: VirtualOrigin;

Defined in: packages/db/src/virtual-props.ts:85

Origin of the last confirmed change to this row, from the current client's perspective.

  • 'local': The change originated from this client
  • 'remote': The change was received via sync

For local-only collections, this is always 'local'. For live query collections, this is passed through from the source collection.


$synced

ts
readonly $synced: boolean;
readonly $synced: boolean;

Defined in: packages/db/src/virtual-props.ts:74

Whether this row currently has no pending local optimistic writes.

  • true: No pending local optimistic mutation currently affects this row
  • false: One or more pending local optimistic mutations currently affect this row

This is local mutation status. It does not prove that a backend has uploaded, confirmed, or read back the row. If you need backend-confirmed status, keep your mutation function pending until that backend observation has happened, or expose adapter-specific status.

For local-only collections (no sync), this is always true. For live query collections, this is passed through from the source collection.