I'm trying to figure out how to connect to a postgres database, run a query, and then disconnect.
Looking at Postgrex, I establish a connection using
{:ok, pid} = Postgrex.start_link(hostname: "localhost", username: "postgres", password: "postgres", database: "postgres")
Then I execute my query using
Postgrex.query!(pid, "SELECT user_id, text FROM comments", [])
But then, how do I disconnect?
I'd like to disconnect because I am looping through N databases and running the same query on all of them.
I tried exiting the Process e.g. Process.exit(pid, :bye)
, but it kills the spawning process also because it's started with start_link/3
. I can't find a start/3
function in Postgrex
.