Call me lazy or even simple, but I implement "SQL libraries" using a simple subclass of DBIx::Simple.

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;
Somewhere else:
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' }


In reply to Re: RFC: DBIx::Library by Juerd
in thread RFC: DBIx::Library by eric256

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.