Hi, I am planning on using Prisma with next.js. In the examples they show that you should close the connection with prisma. Do I also have to do that with the API routes (see picture from prisma.io/nextjs)
👀 1
t
Tomáš
10/16/2022, 3:34 PM
let prisma handle it, don't close, I think prisma can reuse the connection on the same server when using serverless
b
Bart Westenenk
10/16/2022, 3:50 PM
I did get complaints, so I just made a prisma.ts file in a utils folder and use that to "reuse" my connection
t
Tomáš
10/16/2022, 4:33 PM
Yes, you should export a single client and use that everywhere,
n
Nurul
10/17/2022, 6:33 AM
Hello @Bart Westenenk 👋
Welcome to our community! prisma rainbow
If you want to explicitly disconnect then you can use the $disconnect method, but ideally you should not disconnect in order to reuse the existing connection. You should disconnect only in case if your app runs infrequently (for example, a scheduled job to send emails each night), which means it does not benefit from a long-running connection to the database.
b
Bart Westenenk
10/17/2022, 7:03 AM
Alright, thank you. Is there a way I can close the connection once my app restarts? I am using fast refresh and sometimes it starts to complain that there are a lot of connections
t
Tomáš
10/17/2022, 11:07 AM
I think you could check for process.env.NODE_ENV and disconnect only in dev enviroments
n
Nurul
10/19/2022, 11:31 AM
@Bart Westenenk Are you perhaps running into this issue? Can you check the solution mentioned?