| 1 | import { getDb } from "./db"; |
| 2 | |
| 3 | export async function getLatestPosts(limit = 10) { |
| 4 | const db = getDb(); |
| 5 | const runtime = db.runtime(); |
| 6 | |
| 7 | return runtime.execute( |
| 8 | db.sql.post |
| 9 | .select("title", "excerpt") |
| 10 | .orderBy("createdAt", { direction: "desc" }) |
| 11 | .limit(limit) |
| 12 | .build(), |
| 13 | ); |
| 14 | } |
| 15 | |
| 16 | export async function checkDatabaseReady() { |
| 17 | const db = getDb(); |
| 18 | const runtime = db.runtime(); |
| 19 | await runtime.execute(db.sql.user.select("id").limit(1).build()); |
| 20 | } |