Drizzle pagination with count
Hi, is there a way to have a paginated query that also count all posible results based on a condition? I have the following currently:
Is there a way to do this counting without having to repeat the whole query again?
const result = await db.query.businessUsers
.findMany({
orderBy: businessUsers.id,
limit: limit,
offset: offset,
where: or(
like(businessUsers.id, %${text}%),
like(businessUsers.name, %${text}%),
like(businessUsers.subdomain, %${text}%)
),
})
const count = await db
.select({ count: sql<number>count(*) })
.from(businessUsers)
.where(
or(
like(businessUsers.id, %${text}%),
like(businessUsers.name, %${text}%),
like(businessUsers.subdomain, %${text}%)
)
)Is there a way to do this counting without having to repeat the whole query again?