feat(sql-runtime): add callback-based transaction API#346
Open
aqrln wants to merge 1 commit intotransaction-api-specfrom
Open
feat(sql-runtime): add callback-based transaction API#346aqrln wants to merge 1 commit intotransaction-api-specfrom
aqrln wants to merge 1 commit intotransaction-api-specfrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/emitter
@prisma-next/migration-tools
@prisma-next/vite-plugin-contract-emit
@prisma-next/runtime-executor
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-pipeline-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
This was referenced Apr 15, 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.
PR Stack: Transaction API
maindb.transaction()+tx.sql#345tx.orminto transactions#346Part of https://linear.app/prisma-company/issue/TML-1912/orm-transaction-support
Summary
Implements Milestone 1 of the transaction API: the core
withTransactionhelper insql-runtime(target-agnostic) and thedb.transaction()surface onPostgresClientwithtx.sqlsupport.Implementation
withTransaction(runtime, fn)—@prisma-next/sql-runtimeA target-agnostic helper that manages the full transaction lifecycle:
TransactionContextinvalidated = true→ commits → releases connectioninvalidated = true→ rolls back → releases connection → re-throwsSafety features:
tx.execute()after the transaction ends throwsRUNTIME.TRANSACTION_CLOSEDAsyncGeneratorwraps every result; consuming rows post-commit throws the same error per-yieldRUNTIME.TRANSACTION_ROLLBACK_FAILEDwith the original error as.causePostgresClient.transaction()+PostgresTransactionContextdb.transaction(fn)delegates towithTransaction, attaching a freshDb<TContract>SQL builder astx.sql. Lazy-initializes the runtime on first call (same asconnect()/runtime()).New public exports from
@prisma-next/sql-runtimeTransactionContext(type)RuntimeConnection,RuntimeTransaction,RuntimeQueryable(types — previously internal)withTransaction(function)Tests
Unit tests —
withTransaction(12 tests)Unit tests — Postgres (3 tests)
transaction()delegates towithTransactionwith the lazy runtimetransaction()providessqlon the transaction contexttransaction()lazily creates runtime beforeconnect()Type-level tests (3 tests)
transactionmethod (no nesting)db.transaction()infers callback return type correctlytx.sqlhas the same type asdb.sqlE2E tests against real Postgres (5 tests)
PromiseLikeauto-drain)AsyncIterableResultconsumed after commitKey design decisions
execute()semantics everywhere (ADR 187)RUNTIME.TRANSACTION_CLOSED,RUNTIME.TRANSACTION_ROLLBACK_FAILEDsql-runtime, adapter addstx.sqlsurfacePostgresTransactionContextomitstransaction, enforced at compile timePromiseLike<R>callback return — auto-drainsAsyncIterableResultwhen returned directlyFiles changed
packages/2-sql/5-runtime/src/sql-runtime.ts—withTransaction,TransactionContextpackages/2-sql/5-runtime/src/exports/index.ts— new exportspackages/2-sql/5-runtime/test/sql-runtime.test.ts— 12 unit testspackages/3-extensions/postgres/src/runtime/postgres.ts—db.transaction(),PostgresTransactionContextpackages/3-extensions/postgres/test/postgres.test.ts— 3 unit testspackages/3-extensions/postgres/test/transaction.types.test-d.ts— 3 type tests (new)test/e2e/framework/test/transaction.test.ts— 5 e2e tests (new)projects/orm-client-transaction-api/{plan,spec}.md— mark M1 tasks done