db.query.categories.findMany({
offset,
limit: perPage,
where: eq(categories.userId, userId),
extras: (category, { sql }) => {
return {
postCount:
sql`(SELECT count(*) from posts WHERE category_id = ${category.id})`.as(
'post_count'
),
}
},
})
db.query.categories.findMany({
offset,
limit: perPage,
where: eq(categories.userId, userId),
extras: (category, { sql }) => {
return {
postCount:
sql`(SELECT count(*) from posts WHERE category_id = ${category.id})`.as(
'post_count'
),
}
},
})