Counting rows in Drizzle ORM

Hi, I was wondering what the best way to count rows in drizzle is. Thanks for the help!
Solution:
```ts import { sql } from 'drizzle-orm' import { YOUR_TABLE } from 'schema' const { count } = await db.select({...
Jump to solution
3 Replies
Solution
Neto
Neto12mo ago
import { sql } from 'drizzle-orm'
import { __YOUR_TABLE__ } from 'schema'

const { count } = await db.select({
count: sql<number>`count(*)`.mapWith(Number)
}).from(__YOUR_TABLE__)
import { sql } from 'drizzle-orm'
import { __YOUR_TABLE__ } from 'schema'

const { count } = await db.select({
count: sql<number>`count(*)`.mapWith(Number)
}).from(__YOUR_TABLE__)
Liam
Liam12mo ago
Thanks! That seems to be working.