mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
99 stars 46 forks source link

PG env vars (incl PGSERVICE*) #1

Closed kweetal closed 9 years ago

kweetal commented 9 years ago

Hi,

It seems Mojo::Pg doesn't take PG* environment variables properly into account:

example:

$ env | grep ^PG PGSERVICEFILE=/home/aardvark/.pg_service PGSERVICE=HEAD PGPASSFILE=/home/aardvark/.pg_aardvark

$ grep -A 5 $PGSERVICE $PGSERVICEFILE [HEAD] host=/tmp port=6545 user=aardvark dbname=testdb

they suffice for DBI connect:

$ perl -MDBI -e 'print DBI->connect->selectrow_arrayref("select version()")->[0], "\n"' PostgreSQL 9.5devel_HEAD_20141013_0733_494affbd900d on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.9.1, 64-bit

Seeing the above I reckon the following should have worked too but does not: $ perl -MMojo::Pg -E'say Mojo::Pg->new("dbi:Pg:service=HEAD;");' Invalid PostgreSQL connection string "dbi:Pg:service=HEAD;" at -e line 1.

Likewise, env var DBI_DSN is not used.

Ideally, DBI_DSN='dbi:Pg:' + the above PG-envvars should make connection easy and switchable between pg-versions.

kraih commented 9 years ago

Most environment variables should work now, if you have an idea for how to make more work, please send a pull request.