elixir-ecto / db_connection

Database connection behaviour

Home Page:http://hexdocs.pm/db_connection/DBConnection.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lazy connections

sonic182 opened this issue · comments

db_connection supports lazy pools?

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

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

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

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.