-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathindex.ts
More file actions
38 lines (33 loc) · 918 Bytes
/
index.ts
File metadata and controls
38 lines (33 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { drizzle, type PostgresJsDatabase } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as schema from './schema'
export * from './schema'
export type { PostgresJsDatabase }
const connectionString = process.env.DATABASE_URL!
if (!connectionString) {
throw new Error('Missing DATABASE_URL environment variable')
}
console.log(
'[DB Pool Init]',
JSON.stringify({
timestamp: new Date().toISOString(),
nodeEnv: process.env.NODE_ENV,
action: 'CREATING_CONNECTION_POOL',
poolConfig: {
max: 30,
idle_timeout: 20,
connect_timeout: 30,
prepare: false,
},
pid: process.pid,
isProduction: process.env.NODE_ENV === 'production',
})
)
const postgresClient = postgres(connectionString, {
prepare: false,
idle_timeout: 20,
connect_timeout: 30,
max: 30,
onnotice: () => {},
})
export const db = drizzle(postgresClient, { schema })