I’ve been working on building my first REST API in Clojure. I’ve been dabbling in Clojure for a while on and off and am now attempting to make a more formal go at it with a real project. The relevant libraries I’m using are for this question are:
After doing some research on this and how to use integrant and Ring in this scenario I found several pieces of information suggesting passing the datasource into the handler via middleware which I have working.
But last night I realized i can’t recall from my Java days 15 years ago how that actually is working under the hood. As a point of reference, in a Ruby on Rails application default scenario, ActiveRecord grabs an actual database connection when a controller is instantiated and holds onto it until the response is returned which can have really bad characteristics if you have say a long running downstream API call to an external system because you can run out of database connections under load even though the conn was only needed for a few milliseconds.
So my question boils down to the difference between a datasource and an actual connection to the DB. Is passing the datasource in JDBC parlance simply a reference to said datasource where e.g. hugsql uses the datasource to grab a connection and returns it immediately after the query returns? Or is the way my application is setup more akin to ActiveRecord where assoc’ing the datasource in middleware is grabbing a connection and hanging onto it until the ring handler returns a response?
Thanks for any clarity.