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
The best method would probably be for you to refactor your query to take in multiple objects
this seems like such an oversight imo, might be wrong though
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
thats a smart workaround!
👍
thanks Pod!
np, gl!
@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.
Which does have some nice benefits 👌
oo sweet
@Pod Could i ask you one more question? Its regarding prisma and joins?
For sure
Thanks mate!
I have 2 tables, and would like to do a classic inner join between them, How could i achieve this using prisma?
You can do something along the lines of
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?Yes
right...
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.
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?
I'm assuming you're wanting to just test the db queries right?
precisley
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
so there is no way to see the results in vscode for example in a debugging window
I don't believe so, what you could do is open up prisma studio and see the results there
doesn't that just show me the database?
Yes, but if you're looking to see what the results of the query are you can do it there
Yeah of course - thanks for the help!
np!