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
Neto2y 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
LiamOP2y ago
Thanks! That seems to be working.
Want results from more Discord servers?
Add your server