The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::PgLink::Adapter - DBI wrapper for DBIx::PgLink suite

SYNOPSIS

    use DBIx::PgLink::Adapter;
    $db = DBIx::PgLink::Adapter->new();

    $db->install_roles(qw/NestedTransaction TraceDBI/);

    $db->install_roles('Reconnect');
    $db->reconnect_retries(10);

    $db->connect("dbi:Pg:host=127.0.0.1;db=postgres", "postgres", "", { RaiseError=>1, AutoCommit=>1 });

    $db->do("SET client_min_messages=INFO");

    $db->dbh->{'pg_enable_utf8'} = 1;

    $st = $db->prepare("SELECT * FROM pg_database");
    $st->execute;
    @row = $st->fetchrow_array;

See also DBIx::PgLink

DESCRIPTION

Class wraps DBI database handle and provides base for further extending.

Used Moose object system.

Extending

Extending can be made by subclassing for specific data source type and/or by adding roles.

Subclasses of DBIx::PgLink::Adapter may implement missing or broken functionality of DBD driver or underlying driver/database.

Roles (a.k.a. traits or mixins) supply additional functionality and may be composed in any combinations (in theory). Adapter can load role: 1) in compile-time via with clause 2) in run-time via install_role subroutine or via direct meta-class manipulation.

Descendant adapter classes and extra roles can have any name.

DATABASE OBJECT

METHODS

new(%attr)

Default constructor.

connect($data_source, $user, $password, \%attr)

Connect to DBI datasource. Returns database handle.

install_roles

Apply roles to current object. Role name can be full package name or just last portion, which defaults to 'DBIx::PgLink::Roles::' namespace.

err errstr state set_err func data_sources do last_insert_id selectrow_array selectrow_arrayref selectrow_hashref selectall_arrayref selectall_hashref selectcol_arrayref prepare prepare_cached commit rollback begin_work disconnect ping get_info table_info column_info primary_key_info primary_key foreign_key_info statistics_info tables type_info_all type_info quote quote_identifier

Methods of DBI database handle. Can be overrided and extended.

All methods that should return statement handle returns instance of <DBIx::PgLink::Adapter::st> class instead.

is_transaction_active

Utility function. Return true if connection is in transaction.

format_routine_call
  $sql = $adapter->format_routine_call($catalog, $schema, $routine, $returns_set, \@args);

Generate SQL query for routine call.

$returns_set is boolean, pass true if routine returns set.

\@args is array of hashes for routine arguments. For database that supports named arguments each entry must contains 'arg_name' value.

Generic implementation use 'SELECT' keyword with positional call syntax (PostgreSQL-compatible).

ATTRIBUTES

NOTE: DBI attributes are not imported. Use dbh attribute for direct access.

connector

Weak reference to optional parent of DBIx::PgLink::Connector class. Read only.

dbh

Wrapped DBI database handle.

STATEMENT OBJECT

Statement object created by prepare database method.

METHODS

err errstr state set_err trace trace_msg func bind_param bind_param_inout bind_param_array execute execute_array execute_for_fetch fetchrow_arrayref fetchrow_array fetchrow_hashref fetchall_arrayref fetchall_hashref finish rows bind_col bind_columns dump_results

Methods of DBI statement handle. Can be overrided and extended.

ATTRIBUTES

parent

Link to Adapter instance. Read only.

sth

Wrapped DBI statement handle. Read only.

Why another DBIx wrapper?

I need this features:

1) Cross-database support 2) Easy extending 3) Mixin/trait-like composing of functionality in run time 4) Set of ready pluggable modules. Particular interest in disconnection handling.

DBIx::SQLEngine with DBIx::AnyDBD

+ Good cross-database support - Too ORM-ish. Overkill for data access from one relational engine to another RDBMS.

DBIx::Roles

+ Good set of predifined roles - No cross-database support

CAVEATS

Class construction is really SLOW. It is a price for extensibility. See Moose::Cookbook::WTF.

SEE ALSO

DBI, DBIx::PgLink Moose

AUTHOR

Alexey Sharafutdinov <alexey.s.v.br@gmail.com>

COPYRIGHT AND LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.