Norma::DB - Easy interface to fundamental data access and table definition operations in DBI
use Norma::DB; my $db = Norma::DB->initialize( dsn => 'dbi:mysql:database=testdb', username => 'dbuser', password => 'dbpassword', ); my $id = $db->insert( table_name => 'recipes', values => { title => "Scrambled Eggs", instructions => 'Break two eggs into a bowl...', date_added => sub { 'NOW()' }, ... } ); $db->update( table_name => 'recipes', values => { title => "Delicious Scrambled Eggs" }, where => "id = 1", ); my $recipe = $db->select( table_name => 'recipes', where => "id = 1", ); $db->delete( table_name => 'recipes', where => "id = 1", );
Set up an instance, given some connection criteria and authentication info. Alternatively, pass in an existing database handle as "dbh" if you already have one.
Insert a row, given a table name and values for the row. Values will be escaped using DBI::quote except for subref values. Values that are references to subs will be executed, and their return value subtituted in for that column, useful for calling database functions (e.g. date_created => sub { 'NOW()' }). Returns the primary id for the inserted row.
Similar to insert, but only insert the row if it's not already there (i.e., if it doesn't break a unique constraint). Values are processed as they are in insert(). Return criteria to select the row, whether it was inserted or already there. Implemented nicely in a single query for MySQL, less elegantly for SQLite.
Update rows in a table, given values to update, and matching criteria. Values are processed as they are in insert() Returns the number of rows affected.
Delete rows in a table, given criteria. Returns number of rows affected.
Select rows from a table, given criteria.
Get a table definition, given a table name
Get primary key field names, given a table name.
Get names of columns that have single-column unique/primary indexes, given a table name
DBI is great, but it doesn't cover everything. Norma::DB is augmented by database-specific drivers in order to support some bits of functionality like merge() and get_table_key_field_names()
Norma::DB::MySQL provides support for MySQL Norma::DB::SQLite provides support for SQLite3
David Chester <davidchester@gmx.net>
This software is copyright (c) 2010-2011 by David Chester.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Norma, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Norma
CPAN shell
perl -MCPAN -e shell install Norma
For more information on module installation, please visit the detailed CPAN module installation guide.