Tuesday 28 May 2019

Transaction handling

I need to see if I'm missing something when it comes to Node and PG transactions. We're using postgresql, node-postgres.com. We are not using transactions. Instead the connection pool is a global variable in the data access layer. If any DB component needs to connect to the DB, it just calls db.query (which wraps getting a connection and executes the query for the team). No connections are shared.I want to introduce transactions to most of the code. To this end, I believe that the transaction object has to be passed through the layers of the application in some manner. It could be implicit by using dependency injection and constructors, or explicit like Go's context.When I went with the Go style where every function (ours are mostly static methods right now) gets a transaction, my team says that it's too complex. They think there is a better way.I've been wracking my brain, but I don't see how I can propagate a transaction through the stack without manually handing it down. Is there a way to put it in a global variable like we did with out connection pool?

Submitted May 28, 2019 at 08:57PM by HeavilyFocused

No comments:

Post a Comment