The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Class::DBI::Pg::More - Enhances Class::DBI::Pg with more goodies.

SYNOPSIS

package MyClass;
use base 'Class::DBI::Pg::More';

__PACKAGE__->set_up_table("my_table");

# a_date is a date column in my_table. 
# Class::DBI::Plugin::DateFormat::Pg->has_date has been
# called for a_date implicitly.
my $a_date_info =  __PACKAGE__->pg_column_info('a_date')
print $a_date_info->{type}; # prints "date"

# an_important is an important column in my_table set to not null
print $a_date_info->{is_nullable} ? "TRUE" : "FALSE"; # prints FALSE

DESCRIPTION

This class overrides Class::DBI::Pg set_up_table method to setup more things from the database.

It recognizes date, timestamp etc. columns and calls Class::DBI::Plugin::DateTime::Pg has_* methods on them.

It also fetches some constraint information (currently not null).

METHODS

$class->set_up_table($table, $args)

This is main entry point to the module. Please see Class::DBI::Pg documentation for its description.

This class automagically uses Class::DBI::Plugin::DateTime::Pg for date/time fields, so you should use DateTime values with them.

$class->set_exec_sql($name, $sql, @arg_map)

Wraps Ima::DBI set_sql methods to create exec_$name function which basically calls execute on sql_$name handle.

@arg_map provides mapping of the arguments to the exec function. It can be used to call instance methods to get execution parameters.

For example given "update __TABLE__ set col = ? where id = ?" statement argument map (undef, "id") tells to substitute last parameter by results of the $self->id function.

$class->set_exec_sql($name, $sql, $slice, @arg_map)

Wraps Ima::DBI set_sql methods to create fetch_$name function which basically calls execute and fetchall_arrayref on sql_$name handle.

For description of $slice parameter see DBI fetchall_arrayref function.

@arg_map is described above.

$class->pg_column_info($column)

Returns column information as HASHREF. Currently supported flags are:

type - Returns data type of the column (e.g. integer, text, date etc.).
is_nullable - Indicates whether the $column can be null.

AUTHOR

Boris Sukholitko
CPAN ID: BOSU

boriss@gmail.com

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

Class::DBI::Pg, Class::DBI::Plugin::DateTime::Pg.