This is likely to be a personal preference thing. As Corion says, some people like to write the SQL directly; others prefer a tool. Personally I use SQL::Abstract::More most of the time. I like it more than SQL::Abstract, upon which it is based, because it allows use of named parameters (I hate positional parameters), and also supports more complex clauses such as joins, etc.

Yes, in a way you will be learning one syntax instead of another. But after becoming familiar with it I think you'll find it intuitive and effective. One thing I really like is not having to think at all about quoting values, or even about placeholders. You write your values right into the call to SQL::Abstract::More, and get back the SQL and a list of bind values that will be plugged into the placeholders by the DBI. Here's an example that's based on a recent script I was working on:

use SQL::Abstract::More; my $sql_builder = SQL::Abstract::More->new; my ( $sql, @bind ) = $sql_builder->select( -columns => "id, site_id", -from => "jobs", -where => { id => [ 10 .. 20 ], first_seen_time => [ "null", { "<" => time - 86400, ">" => time - 86400 * 8 }, ], }, ); print " SQL: $sql\n\n"; print "BIND: @bind\n";' ...
Output:
SQL: SELECT id, site_id FROM jobs WHERE ( ( ( first_seen_time = ? OR ( + first_seen_time < ? AND first_seen_time > ? ) ) AND ( id = ? OR id = + ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id = ? OR id += ? OR id = ? OR id = ? ) ) ) BIND: null 1486484465 1485879665 10 11 12 13 14 15 16 17 18 19 20
As you can see the builder adds lots of parentheses, some probably not necessary, but your RDBMS will optimize the query in any case.

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: What Do Monks Think of SQL Query Builders? by 1nickt
in thread What Do Monks Think of SQL Query Builders? by nysus

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.