Initial commit
This commit is contained in:
16
lib/db/index.ts
Normal file
16
lib/db/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { drizzle } from 'drizzle-orm/postgres-js'
|
||||
import postgres from 'postgres'
|
||||
import * as schema from './schema'
|
||||
|
||||
// In Next.js, avoid creating multiple connections in development due to hot reload
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var _pgClient: ReturnType<typeof postgres> | undefined
|
||||
}
|
||||
|
||||
const connectionString = process.env.DATABASE_URL!
|
||||
|
||||
const client = globalThis._pgClient ?? postgres(connectionString)
|
||||
if (process.env.NODE_ENV !== 'production') globalThis._pgClient = client
|
||||
|
||||
export const db = drizzle(client, { schema })
|
||||
Reference in New Issue
Block a user