Open vpzomtrrfrt opened 4 years ago
Not the maintainer, but I was personally unsure about whether this should be part of the [tokio-]postgres
crate or not. I did make it possible to read the environment variables yourself in the meantime, though! (#535)
Here's some example code you can copy/paste if you like:
While I wouldn't want this to happen by default, it seems potentially plausible to have a method on the Config type to do this - Config::new().load_from_env()
or whatever.
It would be great if tokio-postgres
did support the config
crate. In deadpool-postgres
I have create my own Config
struct which is a 1:1 copy of the tokio_postgres::Config
but supports serde
and the config
crate. See https://github.com/bikeshedder/deadpool/blob/master/postgres/src/config.rs#L219
@vpzomtrrfrt If you are using tokio
and need a pool anyways you could use deadpool-postgres
which supports the config
crate. You could even use just the Config
struct from deadpool-postgres
and call the get_pg_config
method, but that would add a lot of unneeded dependencies to your code.
@sfackler Would you like to adopt this code to rust-postgres
? I'd be more than happy to get rid of my own config wrapper and provide a PR for that instead.
As documented here: https://www.postgresql.org/docs/current/libpq-envars.html
libpq can read connection information from environment variables, could this be an option in tokio-postgres as well?