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.
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.
I found one commit by @timsuchanek https://github.com/prisma/prisma/commit/6b026626b159741337ba4b4fe67eca8f9ca9faac
Works since 2.6.0-dev.60 ✅
Most helpful comment
Closed with https://github.com/prisma/prisma-engines/pull/1074. Will be included in the 2.6 release.