clone select query
Hello
I need to 2 queries in parallel like this (select data + count)
let baseQuery = db.selectFrom('event')
if (title) {
baseQuery = baseQuery.where('title', 'ilike', '%' + title + '%')
}
const [data, count] = await Promise.all([
baseQuery.select(['event.id', 'event.title']).execute(),
baseQuery.select(({ fn }) => fn.count('event.id').as('total')).executeTakeFirstOrThrow(),
])
return { data, count }
Is it possible to "clone" the baseQuery in order to make the same query for retrieving the data and the count ?Solution:Jump to solution
No need to clone. The query builder is immutable. Every method call returns a clone (effectively. the implementation is more clever). But you can imagine there's a clone before every method call.
4 Replies
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Solution
No need to clone. The query builder is immutable. Every method call returns a clone (effectively. the implementation is more clever). But you can imagine there's a clone before every method call.
What you have already works
great thanks ! 🙂