Kay Khan
07/11/2022, 10:01 AMKay Khan
07/11/2022, 10:06 AMconst response = await PrismaService.$transaction(
payload.map((p) =>
PrismaService.contract.upsert({
where: { address: p.address },
update: p,
create: p,
})
)
);nikolasburk
upsertMany query in Prisma Client yet. We already have an open feature request for that: https://github.com/prisma/prisma/issues/4134 If you think that would be useful, it would be great if you could leave a 👍 on the GitHub issue and ideally a comment with your use case as well to help us prioritize this in the future 🙂Kay Khan
07/12/2022, 8:01 AMnikolasburk
$transaction (instead of the “interactive” one), where you submit non-resolved Prisma promises as an array, e.g.:
const id = 9 // User to be deleted
const deletePosts = prisma.post.deleteMany({
where: {
userId: id,
},
})
const deleteMessages = prisma.privateMessage.deleteMany({
where: {
userId: id,
},
})
const deleteUser = prisma.user.delete({
where: {
id: id,
},
})
await prisma.$transaction([deletePosts, deleteMessages, deleteUser]) // Operations succeed or fail together
More info about this in the docs 🙂 https://www.prisma.io/docs/guides/performance-and-optimization/prisma-client-transactions-guide#when-to-use-the-transaction-api