Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

feat(orm): add support for runtime virtual fields#654

Open
genu wants to merge 40 commits intozenstackhq:devfrom
genu:feat/add-virtual-fields
Open

feat(orm): add support for runtime virtual fields#654
genu wants to merge 40 commits intozenstackhq:devfrom
genu:feat/add-virtual-fields

Conversation

@genu
Copy link
Copy Markdown
Contributor

@genu genu commented Feb 4, 2026

Adds support for @virtual fields that are computed at JavaScript runtime after query results are returned, complementing the existing @computed fields that are calculated at the database level.

Discord ref: https://discord.com/channels/1035538056146595961/1468213504724045905

Example

// Schema
model User {
    id Int @id
    firstName String
    lastName String
    fullName String @virtual
}

// Client
const client = new ZenStackClient(schema, {
    dialect,
    virtualFields: {
        User: {
            fullName: ({row}) => `${row.firstName} ${row.lastName}`,
        },
    },
});

Summary by CodeRabbit

  • New Features

    • Runtime virtual fields: per-model virtual resolvers (sync/async) run with client/context and attach computed values to query results.
  • Behavior Changes

    • Virtual fields are excluded from DB schema, selection filters, ordering, grouping and aggregates; selecting only virtuals triggers read-back behavior.
    • Result post-processing is now asynchronous and runs with request context; required dependencies for virtuals are fetched automatically.
  • Types & SDK

    • Client options, generated schemas and model typings include virtual field metadata and typings.
  • Tests

    • Comprehensive end-to-end tests for virtual fields.

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants