Skip to content

docs(examples): demonstrate orm in worker transactions#799

Closed
medz wants to merge 1 commit into
prisma:mainfrom
medz:fix/cloudflare-worker-transaction-orm
Closed

docs(examples): demonstrate orm in worker transactions#799
medz wants to merge 1 commit into
prisma:mainfrom
medz:fix/cloudflare-worker-transaction-orm

Conversation

@medz

@medz medz commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Linked issue

n/a — small example change

Summary

The Cloudflare Worker example now shows the ORM client being created from a transaction-scoped runtime, so users can see how ORM writes participate in the same withTransaction body. The ORM client factory accepts RuntimeQueryable, which lets callers pass either the top-level runtime or a transaction scope.

Testing performed

  • pnpm --dir examples/prisma-next-cloudflare-worker typecheck
  • pnpm --dir examples/prisma-next-cloudflare-worker lint
  • pnpm test in examples/prisma-next-cloudflare-worker with Docker Postgres

Skill update

n/a — example-only change

Checklist

  • All commits are signed off (git commit -s) per the DCO. The DCO status check will block merge if any commit is missing a Signed-off-by: trailer.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated (or n/a if the change is doc-only / refactor with no behavioural delta).
  • The PR title is in conventional-commit form.
  • The Skill update section above is filled in (or stated n/a — internal only).

Notes for the reviewer

The example keeps the per-request runtime usage unchanged; only the ORM client factory parameter is widened so transaction scopes can be passed to the same helper.

Summary by CodeRabbit

  • New Features

    • /tx/commit now returns committed status plus the created post and updated user.
  • Improvements

    • Added strict userId format validation for the /tx/commit route.
    • Transaction handling switched to ORM-scoped create/update for clearer behavior.
  • Tests

    • Integration test updated to assert the full /tx/commit JSON response.
  • Documentation

    • Route docs for /tx/commit updated for transaction behavior.

@medz medz requested a review from a team as a code owner June 10, 2026 09:13
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: af082e62-fd10-4921-978b-0e6c334140e2

📥 Commits

Reviewing files that changed from the base of the PR and between e1920af and 1c5300a.

📒 Files selected for processing (4)
  • examples/prisma-next-cloudflare-worker/README.md
  • examples/prisma-next-cloudflare-worker/src/orm-client/client.ts
  • examples/prisma-next-cloudflare-worker/src/worker.ts
  • examples/prisma-next-cloudflare-worker/test/worker.integration.test.ts
✅ Files skipped from review due to trivial changes (1)
  • examples/prisma-next-cloudflare-worker/README.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • examples/prisma-next-cloudflare-worker/test/worker.integration.test.ts
  • examples/prisma-next-cloudflare-worker/src/orm-client/client.ts
  • examples/prisma-next-cloudflare-worker/src/worker.ts

📝 Walkthrough

Walkthrough

The /tx/commit handler was refactored to use a transaction-scoped ORM client (create/update), with a RuntimeQueryable-typed ORM factory, a Char<36> userId guard, an enriched response including created post and updated user, plus updated tests and README.

Changes

ORM-based Transaction Implementation for /tx/commit Route

Layer / File(s) Summary
ORM client type signature update
examples/prisma-next-cloudflare-worker/src/orm-client/client.ts
createOrmClient parameter type changed from Runtime to RuntimeQueryable; imports and context typing updated to ExecutionContext<Contract> from db.context.
Transaction route handler with ORM operations
examples/prisma-next-cloudflare-worker/src/worker.ts
/tx/commit now validates userId as Char<36> using isChar36, runs ORM create/update inside withTransaction via createOrmClient(tx), and returns { committed: true, user, post }.
Integration test for enriched response
examples/prisma-next-cloudflare-worker/test/worker.integration.test.ts
Updated test asserts the full response shape from /tx/commit, including route, committed, and nested user and post fields.
Documentation updates
examples/prisma-next-cloudflare-worker/README.md
Route table note for GET /tx/commit updated to describe transaction-scoped ORM create/update; Known limitations unchanged.

Sequence Diagram(s)

sequenceDiagram
  participant Handler as tx_commit_handler
  participant Validator as isChar36
  participant Transaction as withTransaction
  participant OrmClient as createOrmClient
  participant Database as ORM/DB
  Handler->>Validator: validate userId (length 36)
  Validator-->>Handler: Char<36> userId
  Handler->>Transaction: invoke transactional callback
  Transaction->>OrmClient: build ORM client from tx runtime
  OrmClient->>Database: create Post
  OrmClient->>Database: update User
  Database-->>Transaction: return post and user
  Transaction-->>Handler: return committed, user, post
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • wmadden
  • aqrln

Poem

🐰 In a burrow of bytes I hum and commit,
ORM paws craft posts while users transmit,
Thirty-six chars keep the id snug and tight,
Tests nod approval in morning light,
Docs whisper the change as transactions take flight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: demonstrating ORM usage within worker transactions, which is the primary objective across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@medz medz changed the title fix(examples): demonstrate orm in worker transactions chrome(examples): demonstrate orm in worker transactions Jun 10, 2026
@medz medz changed the title chrome(examples): demonstrate orm in worker transactions fix(examples): demonstrate orm in worker transactions Jun 10, 2026
Signed-off-by: Seven Du <5564821+medz@users.noreply.github.com>
@medz medz force-pushed the fix/cloudflare-worker-transaction-orm branch from e1920af to 1c5300a Compare June 10, 2026 09:16
@medz medz changed the title fix(examples): demonstrate orm in worker transactions docs(examples): demonstrate orm in worker transactions Jun 10, 2026
@medz

medz commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@SevInf SevInf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @medz!

I think correct way to do this would be exposing transaction on postgressServeless facade the same way normal facade does. withTransaction + runtime combination is more of a low-level building block, higher-level transaction is what we meant to expose to end users. It's omission from serverless facade is not some grand design decision, I think we simply forgot.
You could contribute it yourself if you are interested, but fine if it's not — we'd fix it ourself in this case

@medz

medz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

duplicate #695

@medz medz closed this Jun 12, 2026
@medz medz deleted the fix/cloudflare-worker-transaction-orm branch June 12, 2026 05:08
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