import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "@/schemas/schema";
declare global {
var database: PostgresJsDatabase<typeof schema> | undefined;
}
// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(process.env.DATABASE_URL as string, { prepare: false });
const instance = drizzle(client, { schema });
if (process.env.NODE_ENV !== "production") {
global.database = instance;
}
export function getDB(): PostgresJsDatabase<typeof schema> {
return global.database || instance;
}
import { drizzle, type PostgresJsDatabase } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "@/schemas/schema";
declare global {
var database: PostgresJsDatabase<typeof schema> | undefined;
}
// Disable prefetch as it is not supported for "Transaction" pool mode
const client = postgres(process.env.DATABASE_URL as string, { prepare: false });
const instance = drizzle(client, { schema });
if (process.env.NODE_ENV !== "production") {
global.database = instance;
}
export function getDB(): PostgresJsDatabase<typeof schema> {
return global.database || instance;
}