Maybe it is just me, but I look at perl code with SQL queries in it and cringe. I don't know what it is about them, maybe just the raw "not perl" look they have.

In some recent projects, I've attemped to modulize all my mySQL calls. I would avoid direct queries at all costs. I'd make up weird subs and stuck them in a "SQL" package so they would not muck up my real perl code.

So sitting back, looking at all of this from the distance, I've come to the conclusion that there are two possible conclusions:

DBI is tremendously powerful and cannot be leashed.
or
DBI could be effectively "leashed", or at least the more simplistic usage.

Now maybe I'm crazy (and if so, please tell me and I'll just keep telling myself that SQL queries in perl code is not a bad thing.) I am no DBI Power User, as you can probably tell, so this is a shot in the dark for me: I really do not know what kind of response to expect.

It call comes down the question of Is it feasable to write a reusable module that controls DBI? Is there something similar that has been already written that I have missed?

Just off the top of my head, an example interface (quasi-code):

$db = connect(HOST => $host, PASSWORD => $pass, ..); $result = $db->select(TABLE => $table_name, FIELDS => ["one","two","th +ree"],ORDERBY => "two",DESCENDING => 1); print $result->[0]->{"one"};

Again, thats quasi-code, just an example of what I'm thinking of for an "interface." Personally, I would love that sort interface, and I would assume others would too .. ? Would a module like this be worth throwing together for personal use, or am I moron for not already knowing about something similar to this? Or should I suck it up and leave my raw queries in my code? :-D
I'd appreciate any feedback. Thanks.

-billyak


In reply to Leashing DBI by billyak

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.