diff --git a/.env.example b/.env.example index 8c13aae..3d62dc2 100644 --- a/.env.example +++ b/.env.example @@ -17,6 +17,11 @@ DATABASE_URL=postgresql://postgres:devpassword@localhost:5432/typelets_local # For production (example): # DATABASE_URL=postgresql://username:password@hostname:5432/database?sslmode=require +# Database Connection Pooling (OPTIONAL) +# DB_POOL_MAX=20 # Maximum connections in pool (default: 20) +# DB_IDLE_TIMEOUT=20 # Close idle connections after N seconds (default: 20) +# DB_CONNECT_TIMEOUT=10 # Connection timeout in seconds (default: 10) + # Clerk Authentication (REQUIRED) # Get your secret key from: https://dashboard.clerk.com/ # For development, use test keys (sk_test_...) diff --git a/src/db/index.ts b/src/db/index.ts index 44abb10..2442ee3 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -9,6 +9,9 @@ if (!process.env.DATABASE_URL) { const client = postgres.default(process.env.DATABASE_URL, { ssl: process.env.NODE_ENV === "production" ? "require" : false, + max: process.env.DB_POOL_MAX ? parseInt(process.env.DB_POOL_MAX) : 20, + idle_timeout: process.env.DB_IDLE_TIMEOUT ? parseInt(process.env.DB_IDLE_TIMEOUT) : 20, + connect_timeout: process.env.DB_CONNECT_TIMEOUT ? parseInt(process.env.DB_CONNECT_TIMEOUT) : 10, }); export const db = drizzle(client, { schema });