Pg::CLI::psql - Wrapper for the psql utility
version 0.11
my $psql = Pg::CLI::psql->new( username => 'foo', password => 'bar', host => 'pg.example.com', port => 5433, ); $psql->run( database => 'database', options => [ '-c', 'DELETE FROM table' ], ); $psql->execute_file( database => 'database', file => 'thing.sql', ); my $errors; $psql->run( database => 'foo', stdin => \$sql, stderr => \$errors, );
This class provides a wrapper for the psql utility.
This class provides the following methods:
The constructor accepts a number of parameters:
executable
The path to psql. By default, this will look for psql in your path and throw an error if it cannot be found.
username
The username to use when connecting to the database. Optional.
password
The password to use when connecting to the database. Optional.
host
The host to use when connecting to the database. Optional.
port
The port to use when connecting to the database. Optional.
require_ssl
If this is true, then the PGSSLMODE environment variable will be set to "require" when connecting to the database.
PGSSLMODE
quiet
This defaults to true. When true, the "-q" flag is passed to psql whenever it is executed.
This method runs a command against the specified database. You must pass one or more options that indicate what psql should do.
This method also accepts optional stdin, stdout, and stderr parameters. These parameters can be any defined value that could be passed as the relevant parameter to IPC::Run3's run3 subroutine.
stdin
stdout
stderr
run3
Most notably, you can pass scalar references to pipe data in via the stdin parameter or capture output sent to stdout or stderr
This method executes the specified file against the database. You can also pass additional options via the options parameter.
options
This method also accepts optional stdin, stdout, and stderr parameters, just like the $psql->run() method.
$psql->run()
Returns a the three part version as a string.
Returns the first two decimal numbers in the version.
See Pg::CLI for bug reporting details.
Dave Rolsky <autarch@urth.org>
This software is Copyright (c) 2013 by Dave Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Pg::CLI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pg::CLI
CPAN shell
perl -MCPAN -e shell install Pg::CLI
For more information on module installation, please visit the detailed CPAN module installation guide.