multiple query in trpc endpoint
hello guys, i got a question is it possible to perform multiple query in single trpc endpoint, im still new to t3 so i cant find a solution to this
example:
1. create data in table A
2. and then update a value in table B
is there any solution to this? thanks in advance
2 Replies
hey! yes, the endpoint is merely a function.
within that function you can write the logic you just mentioned in the example.
one db call to create data in table A
then another db call to update data in table B
I would recommend doing a
transaction
as it's a mutation in the database, and any errors on both those mutations will put the data in a bad state. and if it's within a transaction, it won't commit those changes 🙂
since you are using prisma, i'd recommend looking at their docs
https://www.prisma.io/docs/concepts/components/prisma-client/transactions#interactive-transactions-in-preview
this should cover what i mentioned earlier 🙂Prisma
Transactions and batch queries (Reference)
This page explains the transactions API of Prisma Client.
ahhh thanksss!!🙌