Hi, I am planning on using Prisma with next.js. In...
# orm-help
b
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
let prisma handle it, don't close, I think prisma can reuse the connection on the same server when using serverless
b
I did get complaints, so I just made a prisma.ts file in a utils folder and use that to "reuse" my connection
t
Yes, you should export a single client and use that everywhere,
n
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
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
I think you could check for process.env.NODE_ENV and disconnect only in dev enviroments
n
@Bart Westenenk Are you perhaps running into this issue? Can you check the solution mentioned?