Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Populating an array via a DBI call - simplified

by ablanke (Prior)
on Apr 01, 2017 at 10:11 UTC ( #1186670=note: print w/replies, xml ) Need Help??


in reply to Populating an array via a DBI call - simplified

Hi,

my personal choice for a easy to use DBI interface is DBIx::Simple.

For your task i took the example from DBIx::Simple::Examples:

my @names = $db->query('SELECT name FROM people WHERE id > 5')->flat;

Replies are listed 'Best First'.
[OT] Re^2: Populating an array via a DBI call - simplified
by erix (Prior) on Apr 01, 2017 at 12:55 UTC

    Slightly [OT]...

    my @names = $db->query('SELECT name FROM people WHERE id > 5')->flat;

    I thought that looked nice so I had a look at it. But when compared to the 'normal' DBI way it turns out there is really not much of an advantage. The line is a little shorter (++) but you get a dependency (--) and lose quite a bit of speed (--).

    perl -MData::Dumper -MDBI -MDBIx::Simple -e ' my $db1 = DBI->connect; # (uses defaults to connect) my $db2 = DBIx::Simple->connect; use Benchmark qw( cmpthese ) ; my $COUNT = -20; print "-- COUNT [$COUNT]\n"; cmpthese( $COUNT, { selectrow_arrayref => sub { my @arr = @{ $db1->selectrow_arrayref( + "select i from generate_series(1,10) as f(i) where i > 5" ) }; }, dbix_query_flat => sub { my @arr = $db2->query( "select i from +generate_series(1,10) as f(i) where i > 5")->flat; }, }); ' -- COUNT [-20] Rate dbix_query_flat selectrow_arrayref dbix_query_flat 5608/s -- -23% selectrow_arrayref 7293/s 30% --

    As always when I look closer at ORMy things (mainly because many people seem to be fond of ORMs), I don't think it's worth it.

      Hi erix,

      first of all ++ for your post. That are the choices you have to made.

      Slightly OT...

      Yes, i tried to see the OP from a different angle.

      As always when I look closer at ORMy things...

      I don't think it's too ORMy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1186670]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2023-12-10 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (40 votes). Check out past polls.

    Notices?