Nivedita Singh
07/09/2021, 11:01 AMNivedita Singh
07/09/2021, 11:31 AMRyan
07/09/2021, 11:45 AMprisma.$executeRaw
.
As for this implementation, I would recommend either using a transaction for this or using a random uuid
instead of incrementing numbers as this would cause conflicts if multiple parallel inserts are made.
This is because it relies on the max value of the last record and that could be same for two parallel requests.Nivedita Singh
07/09/2021, 12:38 PMNivedita Singh
07/10/2021, 9:50 AMconst user = await ctx.prisma.$queryRaw(
`INSERT INTO user (name, custom_id) VALUES ("someName",ย (SELECT IFNULL(MAX(custom_id) + 1,1) from user where company_id = someId))`
)
Here getting user as []. Also I tried without custom_id still getting empty array in variable.Nivedita Singh
07/10/2021, 10:01 AMprisma.$executeRaw
gives number of affected raws but I need inserted record id for further query in resolverRyan
07/12/2021, 5:24 AMconst user = await ctx.prisma.$queryRaw(
`INSERT INTO user (name, custom_id) VALUES ("someName",ย (SELECT IFNULL(MAX(custom_id) + 1,1) from user where company_id = someId)) returning *`
)
This will return the values created.Nivedita Singh
07/12/2021, 7:07 AMRyan
08/12/2021, 6:29 AMNivedita Singh
02/25/2022, 12:59 PM