Shubham Singh
01/06/2021, 10:10 PM{
a Int
b Int
c Int
sum Int
}
is there any way to calculate and assign this `sum as the value of a,b,c`without applying in node js like I see in nosql dataRyan
01/07/2021, 6:20 AMschema.prisma
as follows:
model Data {
id Int @id @default(autoincrement())
a Int
b Int
c Int
sum Int
}
Then run the following command:
prisma migrate dev --create-only --preview-feature
Alter the created .sql
file in the migrations
folder to:
CREATE TABLE "Data" (
"id" SERIAL,
"a" INTEGER NOT NULL,
"b" INTEGER NOT NULL,
"c" INTEGER NOT NULL,
"sum" int generated always as (a + b + c) stored,
PRIMARY KEY ("id")
);
This will always calculate the sum field as a combination of the three values.Keanu Gargar
01/07/2021, 6:55 AMgenerated always as (a + b + c) stored
i have a hard time looking this up on Prisma docs, do you have a link for this? thanks @RyanRyan
01/07/2021, 6:56 AMKeanu Gargar
01/07/2021, 6:57 AMShubham Singh
01/07/2021, 8:15 AM