This commit is contained in:
2025-04-07 18:21:55 +02:00
parent b357057d7b
commit b91161da3a
4 changed files with 134 additions and 14 deletions

View File

@@ -1,18 +1,31 @@
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
// import { drizzle } from "drizzle-orm/postgres-js";
// import postgres from "postgres";
import { env } from "~/env";
import * as schema from "./schema";
/**
* Cache the database connection in development. This avoids creating a new connection on every HMR
* update.
*/
const globalForDb = globalThis as unknown as {
conn: postgres.Sql | undefined;
};
// /**
// * Cache the database connection in development. This avoids creating a new connection on every HMR
// * update.
// */
// const globalForDb = globalThis as unknown as {
// conn: postgres.Sql | undefined;
// };
const conn = globalForDb.conn ?? postgres(env.DATABASE_URL);
if (env.NODE_ENV !== "production") globalForDb.conn = conn;
// const conn = globalForDb.conn ?? postgres(env.DATABASE_URL);
// if (env.NODE_ENV !== "production") globalForDb.conn = conn;
export const db = drizzle(conn, { schema });
// export const db = drizzle(conn, { schema });
// ========== vercel snippet =================
import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
// import { config } from "dotenv";
// config({ path: ".env" }); // or .env.local
// const sql = neon(process.env.DATABASE_URL!);
const sql = neon(env.DATABASE_URL!);
export const db = drizzle({ client: sql,schema: schema });