Prisma-client-js: Introduce number type operations

Created on 16 Apr 2020  路  7Comments  路  Source: prisma/prisma-client-js

SQL allows to atomically operate on number types, included but not limited to incrementing or decrementing a value:

UPDATE posts SET views = views + 1 WHERE ...

This should be possible with Prisma as well. Users are doing ugly workarounds.

Proposed syntax:

await prisma.user.updateMany({
  where: {},
  data: 
    age: {
      set: 18, // this just sets the value, previous syntax is `data: { age: 18 }`
      // or
      increment: 1, // views = views + 1
      // or
      decrement: 2, // views = views - 2
      // or
      multiply: 3, // views = views * 3
      // or
      divide: 4, // views = views / 4
    },
  },
})
kinfeature

Most helpful comment

This is the reason why I don't use prisma atm

All 7 comments

Related: This is also being addressed in the upcoming client API https://github.com/prisma/specs/issues/356

image

This was a very much wanted feature for Prisma 1: https://github.com/prisma/prisma1/issues/1349

I need this so much!

This is the reason why I don't use prisma atm

Hi,
I went through a first pass shaping the problem and adding some more context in a new issue: https://github.com/prisma/prisma-client-js/issues/775
We will be tracking changes through that one from now on, so feel free to subscribe to it for further updates on the progress.

Hi everyone, since we are now tracking progress on this feature here: https://github.com/prisma/prisma-client-js/issues/775 I will this close this one.

This is now available as a preview feature in 2.6.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FluorescentHallucinogen picture FluorescentHallucinogen  路  3Comments

julien1619 picture julien1619  路  3Comments

MichalLytek picture MichalLytek  路  3Comments

AhmedElywa picture AhmedElywa  路  4Comments

timsuchanek picture timsuchanek  路  4Comments