http://qs321.pair.com?node_id=1188055


in reply to Module for substituting complex criteria into hand-written SQL queries

Check out SQL::Abstract::More, which extends the parent class with more flexible functionality (and uses named params, Blessed Be!)

So you can do something like:

my $sqla = SQL::Abstract::More->new; my $time = time; my $status = 'active'; my ( $sql, @bind ) = $sqla->select( # new users yesterday -columns => 'id, name', -from => 'users', -where => { status => $status, first_seen_time => { '>' => $time - 86400, '<=' => $time, }, }, );
Output:
$sql: 'SELECT id, name FROM users WHERE ( ( ( first_seen_time <= ? AND + first_seen_time > ? ) AND status = ? ) )'; \@bind: [ 1492373509, 1492287109, 'active' ];
As you can see this SQL builder often adds unnecessary parentheses; I don't worry about these since any decent RDBMS will optimize them away.

update: added example and then example output

Hope this helps!


The way forward always starts with a minimal test.