http://qs1969.pair.com?node_id=451644

Item Description: A Simple Database Abstraction

Review Synopsis:

Class::DBI is quite a simple module really, mainly you inherit it's methods and go off about your business.
SQL is no longer a problem in the way of causing minor issues with your code, so you can retrieve, create, update or do any other database modifications necessary with the greatest of ease.
The only requirements are to set up your primary index columns, and the columns you need to use for the selects in a module that inherit's from Class::DBI, and then you have total access to Class::DBI's magic.
(example of setup)

## Main class package My::DBI; use base 'Class::DBI'; my $dsn = "dbi:mysql:***"; my $user = "****"; my $passwd = "****"; __PACKAGE__->set_db('Main', $dsn, $user, $passwd); ## Second class package My::Tables; use base 'My::DBI'; __PACKAGE__->columns( Primary => qw[id] ); __PACKAGE__->columns( All => qw [ id author title date content ip ] ); __PACKAGE__->table('entries');

Other useful methods:
add_constructor
Allows you to construct an SQL query snippet and call it through your object.
Music::CD->add_constructor(new_music => 'year > ?'); my @recent = Music::CD->new_music(2000);

retrieve_from_sql
Allows you to consruct your own SQL query like so:
(NOTE: You inlining the entire WHERE clause)
my @cds = Music::CD->retrieve_from_sql(qq{ artist = 'Ozzy Osbourne' AND title like "%Crazy" AND year <= 1986 ORDER BY year LIMIT 2,3 });

Class::DBI::AbstractSearch A search class provided by Class::DBI that allows you to write arbitrarily complex searches using perl data structures, rather than SQL.
my @music = Music::CD->search_where( artist => [ 'Ozzy', 'Kelly' ], status => { '!=', 'outdated' }, );


These are just a few of the features of Class::DBI that I have found quite useful. Check the module out for yourself, it cut my development time in at least half.