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;
|
||||
}
|
||||
7
database/schema.ts
Normal file
7
database/schema.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { integer, pgTable, varchar } from "drizzle-orm/pg-core";
|
||||
|
||||
export const guestBook = pgTable("guestBook", {
|
||||
id: integer().primaryKey().generatedAlwaysAsIdentity(),
|
||||
name: varchar({ length: 255 }).notNull(),
|
||||
email: varchar({ length: 255 }).notNull().unique(),
|
||||
});
|
||||
Reference in New Issue
Block a user