14 lines
399 B
TypeScript
14 lines
399 B
TypeScript
import postgres from 'postgres';
|
|
|
|
const globalForSql = global as unknown as { sql: postgres.Sql<{}> };
|
|
|
|
const sql = globalForSql.sql || postgres(process.env.DATABASE_URL!, {
|
|
max: 10, // Limit maximum connections
|
|
idle_timeout: 20, // Close idle connections after 20 seconds
|
|
connect_timeout: 10,
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== 'production') globalForSql.sql = sql;
|
|
|
|
export default sql;
|