[Prisma 8] Atomic increment / decrement in ORM `update`

Open
#30,808 1 comment 2 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, postgresql, typescript
Domain
backend, database

Research direction

Start by reading the ORM update API and its update compilation path, then compare the current values-only behavior with the Prisma 6/7 atomic operators described here. Add coverage for increment, decrement, multiply, and divide, including a check that updates compile to one atomic statement. Done means the documented counter update works without a read-modify-write step.

Written by the indexing model from the issue text.

Description

Desired behaviour

await db.orm.public.Wallet.where({ id }).update({ balance: { increment: 50 } }); // SET balance = balance + $1

Prisma 6/7 supported { increment | decrement | multiply | divide } in updates, compiled to a single atomic statement. Prisma 8's ORM update takes values only, so a counter update becomes read-modify-write unless it is written in SQL.

Where the gap surfaces today

Balances, scores, counters and quotas, where a read-modify-write update loses writes under concurrency.

Current workaround

UPDATE … SET x = x + $1 … RETURNING … through the SQL builder / raw SQL.

Environment

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.