[HELP] - How to deal with request scoped lifecycle for database transient connections? #1066
leandrocurioso
started this conversation in
General
Replies: 1 comment
-
May I ask why you're trying to keep a db connection transient to request scope? It sounds like you're going to suffer from trying to open the connection each time in a hot path if you do that. fx.New() is not meant to be placed on a hot path. Also, if you're already using Gin, it should have its own lifecycle methods that you can use for implementing things like connection pools to help you avoid problems like this. I have not seen use cases of using both Gin and Fx at the same time. It might help us understand your use case a bit better if you can describe what exactly you're using Fx for. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using fx + mysql + gin and I need some help to figure out how to turn a database connection scoped.
Let's go through this points:
The project is a rest api and I need to know how can I request a connection during a request and use the same connection during the entire request, then when the request is done I need to close it.
The main point is if I use 2 different repositories in the same request I get 2 diferent connections and this doesn't make sense since the cost of opening a connection is high! I should be able to open a new connection "OnRequestBegin" and release "OnRequestEnd". I worked with some injectors before for other languages but I didn't find anything related to it for FX.
Am I losing something? Does anyone know how to solve this?
Beta Was this translation helpful? Give feedback.
All reactions