Initial commit from create-react-router
This commit is contained in:
17
database/context.ts
Normal file
17
database/context.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
||||
|
||||
import * as schema from "./schema";
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user