Replies: 1 comment 1 reply
-
You can write this using With Clause const cte = db.$with('cte').as(db.select({ ...Action, total: sql.raw(`count(*) over() as total`) }).from(Action).limit(20).offset(20));
const result = await db.with(cte).select({
rows: sql.raw(`array_agg(jsonb_build_object('id', id, 'name', name, 'code', code))`),
total: sql.raw(`max(total)`)
}).from(cte); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. I am struggling to convert this raw query to drizzle. Please help me.
select (select count(*) from "Action") as total , (select json_agg(data) from (select "id", "name", "code" from "Action" limit 20 offset 20) as data) as rows
Beta Was this translation helpful? Give feedback.
All reactions