Class::Classless::DBI - provides a Classless object-oriented database interface
use DBI; use DBIx::Interpolate; use Class::Classless::DBI; my $dbh = DBI->connect(...); my $dbx = DBIx::Interpolate->new($dbh); my $dbo = $Class::Classless::DBI::ROOT->clone; $dbo->{METHODS}->{table} = 'table_name'; $dbo->{METHODS}->{dbx} = $dbx; $dbo->insert_into_table( { values => [ {col1 => 'A', col2 => 'B', col3 => 'C'}, {col1 => 'a', col2 => 'b', col3 => 'c'}, {col1 => '1', col2 => '2', col3 => '3'} ] } ); $dbo->update_table( { values => {col1 => 'i', col2 => 'ii'}, where => {col1 => '1'} } ); $dbo->delete_from_table( { where => {col3 => [qw(C c)]} } ); $dbo->select_from_table(); # [{col1 => 'i', col2 => 'ii', col3 => '3'}]
This module provides basic methods for classless objects to make database calls. It is designed to use DBIx::Interpolate, so future changes to that module are likely to affect this module as well.
delete_from_table
insert_into_table
select_from_table
update_table
These methods do what you would expect them to do. Each method can accept a hashref as its argument. The following keys are used by these methods.
Note: select_from_table returns an arrayref of hashrefs. All other methods return the same information as &DBI::do.
&DBI::do
The value of this key should be a hashref. It allows you to use a key other than the column name when specifying table entries. For instance, the following two queries are equivalent.
$dbo->select_from_table( { where => {id => 5, val => 6} } ); $dbo->select_from_table( { where => {foo => 5, val => 6}, columns => {foo => 'id'} } );
This key applies to the values key for insert_into_table and the where key for the other methods.
This key applies only to select_from_table. Its value should be an arrayref containing the names of columns by which to group results.
This key applies to the methods insert_into_table and update_table. Its value should be a hashref containing (column_name => value) entries. For insert_into_table it may also be an arrayref containing several hashrefs. In that case, each hashref must contain the same number of columns. Column values may also be arrayrefs, in which case a row will be inserted for each element of the referenced array.
This key applies only to select_from_table. Its value should be an arrayref containing the names of columns to select from the table.
This key applies to all methods but insert_into_table. Its value should be a hashref or an arrayref containing hashrefs. Each hashref should contain (column_name => value) entries that should all be satisfied for one row. An empty hashref will match all rows. All rows that match any of the hashrefs will be used. If the arrayref is empty, then no rows will be matched. However, if where is undefined, all rows will be matched. In order to simplify some queries, column values may also be arrayrefs, in which case rows that match any element of the referenced array will be used. For example, the following two queries are identical.
$dbo->select_from_table( { where => [ {id => 5, val => 6}, {id => 5, val => 7}, {id => 6, val => 6}, {id => 6, val => 7} ] } ); $dbo->select_from_table( { where => {id => [5,6], val => [6,7]} } );
make_where_clause
make_from_clause
These methods are used internally by the previous methods but are also available for public use. They generate fragments of SQL queries to be used with SQL::Interpolate. make_where_clause expects the where key to be present in the same format as specified above. make_from_clause expects a key named from in the same format as values in a insert_into_table method call. Both accept the columns key as well.
Mark Tiefenbruck <mdash@cpan.org>
Copyright (c) 2005, Mark Tiefenbruck. All rights reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
L<Class::Classless> L<DBIx::Interpolate> L<Class::DBI>
To install Class::Classless::DBI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Classless::DBI
CPAN shell
perl -MCPAN -e shell install Class::Classless::DBI
For more information on module installation, please visit the detailed CPAN module installation guide.