Is there a way to call a trpc useQuery() multiple times?

I have a list of objects, and i would like to call the useQuery 1 time for every object in order to get some deta. Is there a good way to do this?
27 Replies
Pod
Pod2y ago
The best method would probably be for you to refactor your query to take in multiple objects
Christian Lind
Christian LindOP2y ago
this seems like such an oversight imo, might be wrong though
Pod
Pod2y ago
Can you give a bit more detail on what you're trying to do? If you don't want to get all the data in one query the next best way is probably making a component that has the query attached
Christian Lind
Christian LindOP2y ago
thats a smart workaround!
Pod
Pod2y ago
👍
Christian Lind
Christian LindOP2y ago
thanks Pod!
Pod
Pod2y ago
np, gl!
Pod
Pod2y ago
@Christian Lind There is also this if it makes more sense for your use case https://trpc.io/docs/reactjs/usequeries
useQueries() | tRPC
The useQueries hook can be used to fetch a variable number of queries at the same time using only one hook call.
Pod
Pod2y ago
Which does have some nice benefits 👌
Christian Lind
Christian LindOP2y ago
oo sweet @Pod Could i ask you one more question? Its regarding prisma and joins?
Pod
Pod2y ago
For sure
Christian Lind
Christian LindOP2y ago
Thanks mate! I have 2 tables, and would like to do a classic inner join between them, How could i achieve this using prisma?
Pod
Pod2y ago
You can do something along the lines of
prisma.tableA.findMany({
include: {
tableB: true
}
})
prisma.tableA.findMany({
include: {
tableB: true
}
})
Christian Lind
Christian LindOP2y ago
I have implemented it by using a query raw select * from SeenQuestions JOIN Xyz on SeenQuestions.questionId = Xyz.id where Xyz.subcategory=${input.subCategory} In that case - don't i have to add the relation in the prisma schema?
Pod
Pod2y ago
Yes
Christian Lind
Christian LindOP2y ago
right...
Pod
Pod2y ago
Prisma
Relations (Reference)
A relation is a connection between two models in the Prisma schema. This page explains how you can define one-to-one, one-to-many and many-to-many relations in Prisma.
Christian Lind
Christian LindOP2y ago
appreciate it @Pod Could i ask a third question? Its a short one 🙂 You really seem to know what your talking about so thought i could ask you. When building my trpc functions in the backend and prisma functions - is there a good method of calling the functions without having to call it from the frontend? Like a sort of debugging mode?
Pod
Pod2y ago
I'm assuming you're wanting to just test the db queries right?
Christian Lind
Christian LindOP2y ago
precisley
Pod
Pod2y ago
You could call the trpc query manually through the url, just setup a button to do it, or just write the prisma code somewhere like gSSP where it'll run on page load, personally I would hook it up to the frontend, console log the results if necessary, that way it's closer to what the end result will be
Christian Lind
Christian LindOP2y ago
so there is no way to see the results in vscode for example in a debugging window
Pod
Pod2y ago
I don't believe so, what you could do is open up prisma studio and see the results there
Christian Lind
Christian LindOP2y ago
doesn't that just show me the database?
Pod
Pod2y ago
Yes, but if you're looking to see what the results of the query are you can do it there
Christian Lind
Christian LindOP2y ago
Yeah of course - thanks for the help!
Pod
Pod2y ago
np!
Want results from more Discord servers?
Add your server