mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-20 00:51:20 +00:00
24 lines
513 B
TypeScript
24 lines
513 B
TypeScript
|
|
import { SQL } from "bun"
|
||
|
|
import { drizzle, type BunSQLDatabase } from "drizzle-orm/bun-sql"
|
||
|
|
|
||
|
|
import * as schema from "./schema.ts"
|
||
|
|
|
||
|
|
export type Database = BunSQLDatabase<typeof schema>
|
||
|
|
|
||
|
|
export interface DatabaseConnection {
|
||
|
|
db: Database
|
||
|
|
close: () => Promise<void>
|
||
|
|
}
|
||
|
|
|
||
|
|
export function createDatabase(url: string): DatabaseConnection {
|
||
|
|
if (!url) {
|
||
|
|
throw new Error("DATABASE_URL is required")
|
||
|
|
}
|
||
|
|
|
||
|
|
const client = new SQL({ url })
|
||
|
|
return {
|
||
|
|
db: drizzle({ client, schema }),
|
||
|
|
close: () => client.close(),
|
||
|
|
}
|
||
|
|
}
|