feat: JSON type replacement for Prisma TypedSQL queries#649
Draft
feat: JSON type replacement for Prisma TypedSQL queries#649
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prisma's TypedSQL feature generates
sql/{queryName}.tsfiles with$runtime.JsonValuefor 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
Jsonfields in the schema are matched to TypedSQL result columns by database column name (respecting@map). The generator rewrites theResulttype inside the query's namespace:Nullable columns produce
T | null;json-arraycolumns produceT[]. Unannotated columns fall back tounknownunlessallowAnyis set.Changes
src/handler/typedsql.ts— newhandleTypedSqlFile(): walks the TypeScript AST of a TypedSQL file, finds theResulttype alias inside the query namespace, and replaces JSON column types using the annotation map.src/helpers/dmmf.ts— newbuildTypedSqlColumnAnnotationMap(): builds aMap<columnName, documentation>from allJsonDMMF fields, keyed by@mapdb name when present; first model wins on name collisions.src/on-generate.ts— after processing main client files, callshandleTypedSqlQueries()which iteratesoptions.typedSqland processes eachsql/{name}.tsfile. For old-client mode, createspjtg.tsif TypedSQL queries are present and it doesn't yet exist.test/schemas/typedsql.prisma+test/types/typedsql.test-d.ts— E2E schema withtypedSqlpreview feature andtsdtype 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 TypedSQLsql/*.tsrewrite path is exercised entirely via unit tests. Full SQL E2E (with a live PostgreSQL and actual.sqlquery 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/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+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 {"product":"prisma","version":"7.5.0","cli_install_type":"local","information":"","local_timestamp":"2026-03-19T00:26:31Z","project_hash":"6e950066","cli_path":"/home/REDACTED/work/prisma-json-types-generator/prisma-json-types-generator/node_modules/prisma/(dns block)/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+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 {"product":"prisma","version":"7.5.0","cli_install_type":"local","information":"","local_timestamp":"2026-03-19T00:46:35Z","project_hash":"6e950066","cli_path":"/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)/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+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 {"product":"prisma","version":"7.5.0","cli_install_type":"local","information":"","local_timestamp":"2026-03-19T00:46:45Z","project_hash":"6e950066","cli_path":"/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.