Files
evilspins/server/api/card/random.ts
valere 7fa6f6ccc8
All checks were successful
Deploy App / build (push) Successful in 2m15s
Deploy App / deploy (push) Successful in 27s
sql server + platine v2
2026-02-06 22:52:02 +01:00

16 lines
438 B
TypeScript

import { useDB, schema } from '../../db'
import { sql } from 'drizzle-orm'
export default defineEventHandler(async (event) => {
const db = useDB()
const count = await db
.select({ count: sql<number>`count(*)` })
.from(schema.cards)
.get()
const randomOffset = Math.floor(Math.random() * count.count)
const randomCard = await db.select().from(schema.cards).limit(1).offset(randomOffset).get()
return randomCard
})