This commit is contained in:
12
server/api/todos/stats.ts
Normal file
12
server/api/todos/stats.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { db, schema } from 'hub:db'
|
||||
import { sql } from 'drizzle-orm'
|
||||
|
||||
export default eventHandler(async () => {
|
||||
// Count the total number of todos
|
||||
const result = await db.select({
|
||||
todos: sql<number>`count(*)`,
|
||||
users: sql<number>`count(distinct(${schema.todos.userId}))`
|
||||
}).from(schema.todos)
|
||||
|
||||
return result[0]
|
||||
})
|
||||
Reference in New Issue
Block a user