Prisma-client-js: Implement step 1 of atomic operations on update

Created on 21 Aug 2020  Â·  4Comments  Â·  Source: prisma/prisma-client-js

https://github.com/prisma/prisma-client-js/issues/775#issuecomment-674061667 describes 3 steps of implementation work of atomic operations on update. This issue is for the implementation of step 1.

enginequery engine kinfeature tecengines tectypescript

Most helpful comment

Closed with https://github.com/prisma/prisma-engines/pull/1074. Will be included in the 2.6 release.

All 4 comments

Closed with https://github.com/prisma/prisma-engines/pull/1074. Will be included in the 2.6 release.

I noticed that there was no test for this feature, so I decided to write some but it doesn't work due to a bug in client it seems.

Reproduction
In 2.6.0-dev.56

import { PrismaClient } from "@prisma/client";

async function main() {
  const db = new PrismaClient();

  await db.user.create({
    data: {
      email: "[email protected]",
      name: "Bobby Brown Sqlite",
    },
  });

  const result = await db.user.update({
    where: {
      email: "[email protected]",
    },
    data: {
      countInt: {
        // set: null,
        set: 123,
        // increment: 1,
        // decrement: 1,
        // multiply: 2,
        // divide: 1,
      },
      countIntDefault: {
        // set: null,
        // set: 123,
        increment: 1,
        // decrement: 1,
        // multiply: 2,
        // divide: 1,
      },
    },
  });

  console.log(result);
  db.$disconnect();
}

main();
generator client {
  provider = "prisma-client-js"
  previewFeatures = ["atomicNumberOperations"]
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model User {
  id      Int      @default(autoincrement()) @id
  email   String   @unique
  name    String?
  countInt Int?
  countFloat Float?
  countIntDefault Int @default(99)
  countFloatDefault Float @default(99.9)
}

The dmmf has the new properties but it errors with

Failed to validate the query `Error occurred during query validation & transformation:
Mutation (object)
  ↳ updateOneUser (field)
    ↳ data (argument)
      ↳ UserUpdateInput (object)
        ↳ countInt (field)
          ↳ NullableIntFieldUpdateOperationsInput (object)
            ↳ set (field)
              ↳ Value types mismatch. Have: Object({"set": Int(123)}), want: Scalar(Int)` at `.Mutation.updateOneUser.data.UserUpdateInput.countInt.NullableIntFieldUpdateOperationsInput.set`
    at PrismaClientFetcher.request (/Users/j42/Dev/repro/atomic/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:1180:15)

We should make sure to have a proper integration test before we close issues about new features in the future I think.

I'll let @timsuchanek work on fixing this as he was working on it for the TypeScript part 😃

Based on the info that was available I think this is how I'm supposed to used that feature but feel free to correct me if it's not.

Works since 2.6.0-dev.60 ✅

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julien1619 picture julien1619  Â·  3Comments

divyenduz picture divyenduz  Â·  3Comments

mrmntte picture mrmntte  Â·  3Comments

williamluke4 picture williamluke4  Â·  3Comments

MichalLytek picture MichalLytek  Â·  3Comments