elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
309 stars 112 forks source link

Lazy connections #267

Closed sonic182 closed 2 years ago

sonic182 commented 2 years ago

db_connection supports lazy pools?

I mean, create connections by demand and close them if idle

josevalim commented 2 years ago

That's not a decision imposed by db_connection. You can async/lazily connect, but you implement it in your callbacks.

sonic182 commented 2 years ago

Is there any example of that?

it is complicated to specify a custom pool module for opts in Repo, it is heavy sticket to the one implemented here in db_connection and the Holder

josevalim commented 2 years ago

Look at Postgrex. It attempts to connect on init, but if it fails, it does so asynchronously. The same principle could be used for laziness. It is a matter of not doing it on init but when the callbacks are invoked.