mirror of https://github.com/TZGyn/shortener
attempt to fix too many db connection using global db client instance
parent
aa2907dad7
commit
2039bc0eb6
@ -1,7 +1,19 @@
|
|||||||
import { drizzle } from 'drizzle-orm/postgres-js'
|
import {
|
||||||
|
drizzle,
|
||||||
|
type PostgresJsDatabase,
|
||||||
|
} from 'drizzle-orm/postgres-js'
|
||||||
import postgres from 'postgres'
|
import postgres from 'postgres'
|
||||||
import * as schema from './schema'
|
import * as schema from './schema'
|
||||||
import { env } from '$env/dynamic/private'
|
import { env } from '$env/dynamic/private'
|
||||||
|
|
||||||
const client = postgres(env.DATABASE_URL)
|
declare global {
|
||||||
export const db = drizzle(client, { schema })
|
var db: PostgresJsDatabase<typeof schema> | undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
let db: PostgresJsDatabase<typeof schema>
|
||||||
|
if (!global.db) {
|
||||||
|
global.db = drizzle(postgres(env.DATABASE_URL), { schema })
|
||||||
|
}
|
||||||
|
db = global.db
|
||||||
|
|
||||||
|
export { db }
|
||||||
|
|||||||
Loading…
Reference in New Issue