File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,16 +2,24 @@ import { PrismaClient } from '@prisma/client'
22
33let prisma : PrismaClient
44
5+ const CONNECTION_LIMIT = 20
6+
7+ function buildDatasourceUrl ( ) : string {
8+ const baseUrl = process . env . DATABASE_URL ?? ''
9+ const separator = baseUrl . includes ( '?' ) ? '&' : '?'
10+ return `${ baseUrl } ${ separator } connection_limit=${ CONNECTION_LIMIT } `
11+ }
12+
513interface CustomNodeJsGlobal extends NodeJS . Global {
614 prisma : PrismaClient
715}
816declare const global : CustomNodeJsGlobal
917
1018if ( process . env . NODE_ENV === 'production' ) {
11- prisma = new PrismaClient ( )
19+ prisma = new PrismaClient ( { datasources : { db : { url : buildDatasourceUrl ( ) } } } )
1220} else {
1321 if ( global . prisma === undefined ) {
14- global . prisma = new PrismaClient ( )
22+ global . prisma = new PrismaClient ( { datasources : { db : { url : buildDatasourceUrl ( ) } } } )
1523 }
1624
1725 prisma = global . prisma
You can’t perform that action at this time.
0 commit comments