Skip to content

feat: JSON type replacement for Prisma TypedSQL queries#649

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-conflicts-typedsql-update-main
Draft

feat: JSON type replacement for Prisma TypedSQL queries#649
Copilot wants to merge 2 commits intomainfrom
copilot/fix-conflicts-typedsql-update-main

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 19, 2026

Prisma's TypedSQL feature generates sql/{queryName}.ts files with $runtime.JsonValue for JSON result columns. This adds support for replacing those types with user-annotated types from the Prisma schema, the same way model field types are replaced.

How it works

Annotations on Json fields in the schema are matched to TypedSQL result columns by database column name (respecting @map). The generator rewrites the Result type inside the query's namespace:

model Order {
  id   Int  @id
  /// ![number]
  meta Json
}
// Before (Prisma-generated)
export namespace getOrderMeta {
  export type Result = {
    id: number
    meta: $runtime.JsonValue
  }
}

// After (this generator)
export namespace getOrderMeta {
  export type Result = {
    id: number
    meta: (number)
  }
}

Nullable columns produce T | null; json-array columns produce T[]. Unannotated columns fall back to unknown unless allowAny is set.

Changes

  • src/handler/typedsql.ts — new handleTypedSqlFile(): walks the TypeScript AST of a TypedSQL file, finds the Result type alias inside the query namespace, and replaces JSON column types using the annotation map.
  • src/helpers/dmmf.ts — new buildTypedSqlColumnAnnotationMap(): builds a Map<columnName, documentation> from all Json DMMF fields, keyed by @map db name when present; first model wins on name collisions.
  • src/on-generate.ts — after processing main client files, calls handleTypedSqlQueries() which iterates options.typedSql and processes each sql/{name}.ts file. For old-client mode, creates pjtg.ts if TypedSQL queries are present and it doesn't yet exist.
  • test/schemas/typedsql.prisma + test/types/typedsql.test-d.ts — E2E schema with typedSql preview feature and tsd type assertions for both literal (![number]) and namespace ([OptionalField]) annotations.
  • test/unit/typedsql.test.ts — 17 unit tests covering literal, namespace, nullable, array, allowAny, unannotated/unknown, and no-match scenarios.

Note on full SQL E2E coverage

The E2E schema has no SQL files (so no DB connection is needed for prisma generate). The TypedSQL sql/*.ts rewrite path is exercised entirely via unit tests. Full SQL E2E (with a live PostgreSQL and actual .sql query files) can be layered on separately in CI.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint.prisma.io
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/.pnpm/prisma@7.5.0_@types&#43;react@19.2.6_react-dom@19.2.0_react@19.2.0__react@19.2.0_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.5.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-03-19T00:26:31Z&#34;,&#34;project_hash&#34;:&#34;6e950066&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/prisma/ (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/.pnpm/prisma@7.5.0_@types&#43;react@19.2.6_react-dom@19.2.0_react@19.2.0__react@19.2.0_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.5.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-03-19T00:46:35Z&#34;,&#34;project_hash&#34;:&#34;6e950066&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/prisma/ _modules/@prisma/generator-helpe/home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/.pnpm/effect@3.18.4/node_modules/effect/dist/cjs/Resource-c _mod�� _modules/@prisma/generator-helper/dist/json-rpc.js _modules/@prisma/generator-helper/dist/chunk-UMIHM3GW.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/.pnpm/prisma@7.5.0_@types&#43;react@19.2.6_react-dom@19.2.0_react@19.2.0__react@19.2.0_typescript@5.9.3/node_modules/prisma/build/child {&#34;product&#34;:&#34;prisma&#34;,&#34;version&#34;:&#34;7.5.0&#34;,&#34;cli_install_type&#34;:&#34;local&#34;,&#34;information&#34;:&#34;&#34;,&#34;local_timestamp&#34;:&#34;2026-03-19T00:46:45Z&#34;,&#34;project_hash&#34;:&#34;6e950066&#34;,&#34;cli_path&#34;:&#34;/home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/prisma/ fp/keys.js fp/p�� fp/subtract.js fp/identical.js fp/overArgs.js fp/without.js fp/flatten.js fp/compose.js fp/invertObj.js fp/s�� fp/symmetricDiffnode_modules/.pnpm/fast-check@3.23.2/node_modules/fast-check/lib/types/arbitraryrm fp/isNull.js fp/update.js fp/method.js fp/union.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@arthurfiorette
Copy link
Copy Markdown
Owner

lets see how copilot manages to fix this one haha

Co-authored-by: arthurfiorette <47537704+arthurfiorette@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix conflicts and update typedsql branch to latest main feat: JSON type replacement for Prisma TypedSQL queries Mar 19, 2026
Copilot AI requested a review from arthurfiorette March 19, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants