16 lines
578 B
TypeScript
16 lines
578 B
TypeScript
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import * as schema from "./schema";
|
|
|
|
const connectionString = process.env.DATABASE_URL || "postgresql://postgres:Aa110011@localhost:5432/fluxent";
|
|
|
|
// 在 Next.js 开发环境下避免热重载创建重复连接池
|
|
const globalForDb = globalThis as unknown as {
|
|
conn: postgres.Sql | undefined;
|
|
};
|
|
|
|
const client = globalForDb.conn ?? postgres(connectionString, { max: 10 });
|
|
if (process.env.NODE_ENV !== "production") globalForDb.conn = client;
|
|
|
|
export const db = drizzle(client, { schema });
|