18 lines
456 B
TypeScript
18 lines
456 B
TypeScript
import postgres from "postgres";
|
|
|
|
declare global {
|
|
// eslint-disable-next-line no-var
|
|
var __pgPool: ReturnType<typeof postgres> | undefined;
|
|
}
|
|
|
|
function createPool() {
|
|
return postgres(process.env.DATABASE_URL!, {
|
|
max: 10,
|
|
idle_timeout: 20,
|
|
connect_timeout: 10,
|
|
ssl: process.env.DATABASE_SSL === "true" ? { rejectUnauthorized: false } : false,
|
|
});
|
|
}
|
|
|
|
export const sql =
|
|
globalThis.__pgPool ?? (globalThis.__pgPool = createPool());
|