NAME
Nitesi::Query::DBI - DBI query engine for Nitesi
SYNOPSIS
$query = Nitesi::Query::DBI->new(dbh => $dbh);
$query->select(table => 'products',
fields => [qw/sku name price/],
where => {price < 5},
order => 'name',
limit => 10);
$query->insert('products', {sku => '9780977920150', name => 'Modern Perl'});
$query->update('products', {media_format => 'CD'}, {media_format => 'CDROM'});
$query->delete('products', {inactive => 1});
DESCRIPTION
This query engine is based on SQL::Abstract and SQL::Abstract::More.
METHODS
init
Initializer, embeds SQL::Abstract::More object inside our Nitesi::Query::DBI object.
select
Runs query and returns records as hash references inside a array reference.
$results = $query->select(table => 'products',
fields => [qw/sku name price/],
where => {price < 5});
print "Our cheap offers: \n\n";
for (@$results) {
print "$_->{name} (SKU: $_->{sku}), only $_->{price}\n";
}
select_field
Runs query and returns value for the first field (or undef).
$name = $query->select_field(table => 'products',
field => 'name',
where => {sku => '9780977920150'});
select_list_field
Runs query and returns a list of the first field for all matching records, e.g.:
@dvd_skus = $query->select_list_field(table => 'products',
field => 'sku',
where => {media_type => 'DVD'});
insert
Runs insert query, e.g.:
$query->insert('products', {sku => '9780977920150', name => 'Modern Perl'});
update
Runs update query, either with positional or name parameters, e.g.:
$updates = $query->update('products', {media_format => 'CD'}, {media_format => 'CDROM'});
$updates = $query->update(table => 'products',
set => {media_format => 'CD'},
where => {media_format => 'CDROM'});
Returns the number of matched/updated records.
delete
Runs delete query, e.g.:
$query->delete('products', {inactive => 1});
dbh
Returns DBI database handle.
sqla
Returns embedded SQL::Abstract::More object.
CAVEATS
Please anticipate API changes in this early state of development.
We don't recommend to use Nitesi::Query::DBI with file backed DBI drivers like DBD::DBM, DBD::CSV, DBD::AnyData or DBD::Excel. In case you want to do this, please install SQL::Statement first, as the statements produced by this module are not understood by DBI::SQL::Nano.
AUTHOR
Stefan Hornburg (Racke), <racke@linuxia.de>
LICENSE AND COPYRIGHT
Copyright 2011 Stefan Hornburg (Racke) <racke@linuxia.de>.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.