in reply to RFC: DBIx::Library
Call me lazy or even simple, but I implement "SQL libraries" using a simple subclass of DBIx::Simple.
Somewhere else:package SmallProject::Database; use base 'DBIx::Simple'; sub connect { my $self = shift; $self->SUPER::connect('dbi:...', 'u', 'p', { RaiseError => 1}); } sub foo { my $self = shift; my ($where, @binds) = $self->abstract->where({ @_ }); $self ->query("SELECT * FROM foo WHERE $where LIMIT 1", @binds) ->hash; } # This could be simpler if SQL::Abstract supported LIMIT clauses: # sub foo { # my $self = shift; # $self->select(foo => '*', { @_ }, \1); # } sub foos { my $self = shift; $self->select(foo => '*', { @_ })->hashes; } 1;
my $db = SmallProject::Database->new; my $foo = $db->foo(id => 15); my @active_foos = $db->foos(active => 1);
I really like Class::DBI in many ways, but it is often too slow for what I need. Note by the way that one should never SELECT * and then not request a hash :)
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
|
|---|