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:
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.
Jump to solution
4 Replies
Unknown User
Unknown User•6mo ago
Message Not Public
Sign In & Join Server To View
Solution
koskimas
koskimas•6mo ago
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.
koskimas
koskimas•6mo ago
What you have already works
Nicolas Bourdin
Nicolas BourdinOP•6mo ago
great thanks ! 🙂
Want results from more Discord servers?
Add your server