feat(db): add database connection setup using drizzle-orm for PostgreSQL

This commit is contained in:
Mauricio Siu
2025-08-24 16:25:04 -06:00
parent c42054b965
commit aa434cbdea

View File

@@ -0,0 +1,21 @@
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
declare global {
var db: PostgresJsDatabase<typeof schema> | undefined;
}
export let db: PostgresJsDatabase<typeof schema>;
if (process.env.NODE_ENV === "production") {
db = drizzle(postgres(process.env.DATABASE_URL!), {
schema,
});
} else {
if (!global.db)
global.db = drizzle(postgres(process.env.DATABASE_URL!), {
schema,
});
db = global.db;
}