2026-06-14 15:36:44 +02:00
|
|
|
import { drizzle } from 'drizzle-orm/postgres-js'
|
|
|
|
|
import postgres from 'postgres'
|
|
|
|
|
import * as schema from './schema'
|
|
|
|
|
|
|
|
|
|
const connectionString = process.env.DATABASE_URL ?? 'postgres://wc:wc@localhost:5432/worldcup'
|
|
|
|
|
|
2026-06-14 15:58:48 +02:00
|
|
|
// DB_PASSWORD is passed separately to avoid URL-encoding issues with special chars
|
|
|
|
|
// (e.g. #, ], = in passwords break URL parsing). Falls back to password in DATABASE_URL for local dev.
|
|
|
|
|
const client = postgres(connectionString, {
|
|
|
|
|
max: 10,
|
|
|
|
|
...(process.env.DB_PASSWORD ? { password: process.env.DB_PASSWORD } : {}),
|
|
|
|
|
})
|
2026-06-14 15:36:44 +02:00
|
|
|
export const db = drizzle(client, { schema })
|
|
|
|
|
|
|
|
|
|
export * from './schema'
|