Test::Environment::Plugin::PostgreSQL - PostreSQL psql function for testing
use Test::Environment qw{ PostgreSQL }; # set database credentials psql( 'database' => $config->{'db'}->{'database'}, 'hostname' => $config->{'db'}->{'hostname'}, 'username' => $config->{'db'}->{'username'}, 'password' => $config->{'db'}->{'password'}, # or skip hostname and database and set them via #'dbi_dsn' => 'dbi:Pg:dbname=dsn_test;host=localhost', ); # execute sql query my @output = psql( 'switches' => '--expanded', 'command' => 'SELECT * FROM Table', # ..., see psql function description for more )
This plugin will export 'psql' function that can be used to execute PostreSQL psql command with lot of options for testing.
Module will prepare %ENV for postgres:
'username' => 'PGUSER', 'password' => 'PGPASSWORD', 'database' => 'PGDATABASE', 'hostname' => 'PGHOST', 'port' => 'PGPORT',
Any postgres connection settings not listed or undef will be deleted from the %ENV hash.
All functions are exported 2 levels up. That is to the use Test::Environment caller.
psql command executed easily. Here is the list of options that can be used.
Option related to the connection to the database.
username password database hostname port
By setting this PostreSQL %ENV variables will be set. So for psql command to the same databse you need to set them only once.
The rest of the option related to the psql command.
command - scalar or array ref of sql commands switches - scalar or array of additional psql switches output_filename - the output will be written to this file (-o) execution_path - before executing psql change to that folder stderr_redirect - will redirect stderr to stdout so that also error appears in the return value debug - turn on debug mode, it can be also done globaly by setting "$ENV{'IN_DEBUG_MODE'} = 1"
Executes command as system and return output.
In debug mode prints command to stderr.
Test::Environment http://search.cpan.org/perldoc?Test::Environment
Jozef Kutej - <jozef@kutej.net>
To install Test::Environment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Environment
CPAN shell
perl -MCPAN -e shell install Test::Environment
For more information on module installation, please visit the detailed CPAN module installation guide.