2025-10-10 23:04:50 -07:00
|
|
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
|
|
|
|
|
|
|
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
|
|
|
|
2026-03-21 09:44:05 -07:00
|
|
|
import type * as schema from "./schema";
|
2025-10-10 23:04:50 -07:00
|
|
|
|
|
|
|
|
export const DatabaseContext = new AsyncLocalStorage<
|
|
|
|
|
PostgresJsDatabase<typeof schema>
|
|
|
|
|
>();
|
|
|
|
|
|
|
|
|
|
export function database() {
|
|
|
|
|
const db = DatabaseContext.getStore();
|
|
|
|
|
if (!db) {
|
|
|
|
|
throw new Error("DatabaseContext not set");
|
|
|
|
|
}
|
|
|
|
|
return db;
|
|
|
|
|
}
|