Files
beer-inventory/app/utils/db.server.ts
T

22 lines
619 B
TypeScript

import { PrismaClient } from "@prisma/client";
import { singleton } from "./singleton.server";
import { getSession } from "~/auth/session";
import { enhance as znenhance } from "@zenstackhq/runtime";
// Hard-code a unique key, so we can look up the client when this module gets re-imported
export const db = singleton(
"prisma",
() => new PrismaClient()
);
export async function enhance(
request : Request
){
const session = await getSession(
request.headers.get("Cookie")
);
const dbe = session.has("user_id") ? znenhance(db, {user: session.get("user")}) : znenhance(db);
return {dbe, session};
}