How to connect to user-specified DB config using Ecto?

I’m making an SQL query builder, so a user would have to be able to connect to a database at runtime.

Thanks for the tip about the adapter. Looking through the code for the Postgres adapter, I found that it used Postgrex. I was able to use Postgrex directly to connect to the database.

{ :ok, pid } = Postgrex.start_link(hostname: "localhost", username: "admin", password: "", database: "my_db")
    result = Postgrex.query!(pid, "select * from some_table limit 1", [])

For now, I’m just going to use it directly in a controller method. However, I imagine that one might need to create an application with a connection pool open if there are lots of queries?