2matto
2matto9mo ago

Where to put clean up code?

I have a DB connection setup in my createContext that I must explicitly close per-request. But I cannot find any good spots in the TRPC lifecycle to make that call. I tried just running it in a middleware, but seemingly that is invoked on each query in a batch independently, whereas I need it to be called once all queries have finished. FWIW: I am using create-t3-app with @vercel/postgres and createClient. Any insight would be appreciated! (There is a similar post from a few years ago that went unanswered, though it was fastify-specific https://discord.com/channels/867764511159091230/1049691729516843048/1049691729516843048)
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
3 Replies
BeBoRE
BeBoRE9mo ago
Would also like to know if this is possible as well, would need to be documented well tho, cleanup of the context shouldn't be used for finishing transactions for instance.
IceAge2OnDVD
IceAge2OnDVD7mo ago
Looking to do the same with Neon DB, any updates?
BeBoRE
BeBoRE7mo ago
Procedures can clean up, createContext cannot Maybe with using? #tRPC context, NeonDB & WebSockets