There are modules that do this and that for you - but they are mostly written based on the authors idea of DB abstraction. I don't like the Class::DBI - not just for performance, but because of IMO strange way of working with it. I like better the approach of others like say SQL::Abstract ...

Some time ago - I started writing my own. And of course implemented stuff that I found useful yet boring to type as it's basically always the same. Sure there are modules that do some (or all) of the stuff my module does - but I'm doing it for practice anyway ;)

What I would like to know is - What do you people want from such a module?

One of the things that I found very useful in working with DB is Singleton pattern. It allows me to set the connection (or for several of them) data once and then simply ask for new instance where ever I need to work with DB - instead of "passing around the code" the initial DBH.

# Somewhere in init stage use DBIx::Handy; # need a better name ... DBIx::Handy->add_db(dsn => 'dbi:mysql:autoreorder', username => 'alex', name => 'oscommerce'); # Then latter my $DB = DBIx::Handy->get_instance(); my $SQL = "SELECT p.products_id, p.products_image, pd.products_name, pd.products_description FROM products p INNER JOIN products_description pd ON p.products_id = pd.products_id WHERE p.products_id = ?"; my $products_data = $DB->execute(sql => $SQL, data => [$form->{id}], database => 'oscommerce')->fetchrow +_hashref(); my $template = $self->load_tmpl('Product/details.dwt'); $template->param(%{$products_data}); return $template->output();

I didn't felt the need to add much SQL generation functions as I usually have either very simple or very complex queries (that I couldn't generate with abstraction modules). But it does generate SQL for simple INSERT and UPDATE statements.

It simply compares the table columns to keys in hash provided (data to be written) and only include those fields that are found in both.

So for instance you get hash (hashref) from CGI.pm, pass it througth Data::FormValidator and forward it to DBIx::Handy for update/insert.

Another thing that I added recently is possibility to return AoH reference from a query. I very often need those to print search results. And I just pass the reference to say HTML::Template.

my $schools = $DB->execute(sql =>'SELECT * FROM users ORDER BY us +ername', method =>'fetchall_aohref'); my $t = $self->load_tmpl('Admin/view_admin_users.dwt'); $t->param('schools' => $schools); return $t->output();

Currently everything is MySQL specific (might work on other DB's) but I'm looking for a way to support other RDBMS as well. Either through sub classing and overriding needed methods, or in a similar way DBI does it with all DBD::XYZ modules ...


Have you tried freelancing? Check out Scriptlance - I work there.

In reply to What do people want from DB abstraction modules? by techcode

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.