kgni
tRPC context, NeonDB & WebSockets
Well, I spoke with a guy that works at neon, and he made me aware that "The pool is initially created empty and will create new clients lazily as they are needed.", so all of this is not necessary 🙃 The only thing I need in my case is to have a middleware that closes/ends the pool after the response.
15 replies
tRPC context, NeonDB & WebSockets
With this implementation, wouldn't it always be open, which I don't want.. sorry for not being clear enough
per neondb documentation it is advised to close the db connection after every response. So I want to open it when I need it (only in specific procedures) and close it after it is done
15 replies
tRPC context, NeonDB & WebSockets
Ah I see, so you could technically split it up as follows:
1. Create the Websocket database instance in a middleware and then pass it to the context - instead of creating it directly in the context (you could also close the pool in the middleware then).
2. Recreate all of your procedures, so that you have 2 different types - 1 that utilizes HTTP and 1 for websockets, for example:
- publicProcedure, protectedProcedure (both just have the HTTP database instance)
- publicProcedureWebSocketets, protectedProcedureWebSockets.
Would that be a way of doing it to avoid opening the websocket connection every single time the context is created? Also, would there be a smarter way of doing this, than to recreate all of the procedures with websockets (seems a bit too repetitive and redundant)
15 replies
tRPC context, NeonDB & WebSockets
I'm using the neon serverless driver to create a drizzle client which connects over websockets, I just don't know if this connection will open everytime the context is created. I don't want that to happen when/if I'm only querying the database over HTTP.
I hope I'm making sense.
Essentially I have:
2 different db clients created in context.
As far as I know context is created every time a procedure runs. So if I create a client with a pool like this:
Then the connection would technically open every time the context is created right? Or is it only when I'm actually using the client?
I want the connection to only open when it is used and not when context is created.
15 replies