NAME
DBIx::Pg::CallFunction - Simple interface for calling PostgreSQL functions from Perl
VERSION
version 0.019
SYNOPSIS
use DBI;
use DBIx::Pg::CallFunction;
my $dbh = DBI->connect("dbi:Pg:dbname=joel", 'joel', '');
my $pg = DBIx::Pg::CallFunction->new($dbh);
Returning single-row single-column values:
my $userid = $pg->get_userid_by_username({'username' => 'joel'});
# returns scalar 123
Returning multi-row single-column values:
my $hosts = $pg->get_user_hosts({userid => 123});
# returns array ref ['127.0.0.1', '192.168.0.1', ...]
Returning single-row multi-column values:
my $user_details = $pg->get_user_details({userid => 123});
# returns hash ref { firstname=>..., lastname=>... }
Returning multi-row multi-column values:
my $user_friends = $pg->get_user_friends({userid => 123});
# returns array ref of hash refs [{ userid=>..., firstname=>..., lastname=>...}, ...]
DESCRIPTION
This module provides a simple efficient way to call PostgreSQL functions with from Perl code. It only support functions with named arguments, or functions with no arguments at all. This limitation reduces the mapping complexity, as multiple functions in PostgreSQL can share the same name, but with different input argument types.
Please see pg_proc_jsonrpc.psgi for an example on how to use this module.
CONSTRUCTOR METHODS
The following constructor methods are available:
- my $pg = DBIx::Pg::CallFunction->new($dbh, [$hashref])
-
This method constructs a new
DBIx::Pg::CallFunction
object and returns it.$dbh is a handle to your database connection.
$hashref is an optional reference to a hash containing configuration parameters. If it not present, the default values will be used.
CONFIGURATION PARAMETERS
The following configuration parameters are available:
- EnableFunctionLookupCache
-
When enabled, the procedure returns set for each function will be cached. This is disabled by default.
- RaiseError
-
By default, this is enabled. It is used like "RaiseError" in DBI.
REQUEST METHODS
- my $output = $pg->$name_of_stored_procedure($hashref_of_input_arguments)
- my $output = $pg->$name_of_stored_procedure($hashref_of_input_arguments, $namespace)
SEE ALSO
This module is built on top of DBI, and you need to use that module (and the appropriate DBD::Pg driver) to establish a database connection.
There is another module providing about the same functionality, but without support for named arguments for PostgreSQL. Have a look at this one if you need to access functions without named arguments, or if you are using Oracle:
LIMITATIONS
Requires PostgreSQL 9.0 or later. Only supports stored procedures / functions with named input arguments.
AUTHOR
Joel Jacobson http://www.joelonsql.com
COPYRIGHT
Copyright (c) Joel Jacobson, Sweden, 2012. All rights reserved.
This software is released under the MIT license cited below.
The "MIT" License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# vim: ts=8:sw=4:sts=4:et