Yes a Tied interface is what is called for here (two Tied interfaces? one for the database lookup of a table (since there can be only one table of a given name in a database) and one for a table lookup of a row) but the requirement for composite keys makes the behavior quite a bit different from Tie::DBI.

An extreme simplification of the Tied interface would make the first level of hash specify the database server type (ie: server=>'dbi:mysql'), the second level hash specify the credentials (ie: {user=>..., password=>...}), a third level specifying the database name (ie: {$database_name=>{...}}) and then the rest of the hashes behave as previously described for tables and fields.

Also, if something is underspecified, it might return an array; but if it worked that way, the row and field hash interfaces would have to always go through an array ref, ie:

$baz=$object->[0]->{baz}->[0]; $qux=$object->[0]->{qux}->[0];
Blech... But I suppose the schema could restrict that mess to when that level of indirection was required.

Finally, I suppose insertion of a row could also take the form of a 'new' method on the table:

$table->new({baz=>$baz,$qux=>$qux,...});

And if there is an autoincrement key (like 'id'), leaving it out would imply its value to be the next incremented value of that field for that table.


In reply to Re^2: Drop dead simple MySQL interface? by jabowery
in thread Drop dead simple MySQL interface? by jabowery

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.