Is it okay to use transactions to group queries #1507
ChoaibMouhrach
started this conversation in
General
Replies: 1 comment 2 replies
-
You don't need to run this in 2 queries or a transaction. You just need a window function: db.query.categories.findMany({
where,
offset,
limit,
extras: {
count: sql`count(*) over()`.as("count")
}
}), |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question ?
I utilize an endpoint that triggers two queries—one to retrieve records and another to obtain the count—for client-side pagination. While I currently execute these queries using Promise.all(), my understanding from the documentation suggests that it's possible to send both queries in a single transaction and receive their results simultaneously.
What I'm hoping to achieve with this?
One request rather than two
Example?
Is this the optimal approach, and what potential drawbacks does it entail?
Beta Was this translation helpful? Give feedback.
All reactions