Do Moose and DBIx::Class go together like bread and butter? I'm currently using Moose and DBIx::Simple but I have a sneaking feeling that DBIx::Class would be sheer nirvana in this situation.

OK, so I have a bunch of classes which all inherit a base class method to obtain new data:

sub getnew { my ($self) = @_; $self->dbs->query($self->getnewsql)->hashes; }
Now, getnewsql is a lazy-built method. In the first level of derived classes, the following role is used by some classes to get new data:
package Local::GetDataTable; use Moose::Role; sub _build_getnewsql { my ($self)=@_; sprintf "SELECT * FROM %s WHERE qblistid IS NULL and qbresponse IS N +ULL", $self->dbtable; }; 1;
Now, in a class which needs to refine the WHERE clause with another clause, we override this lazy builder as follows:
override '_build_getnewsql' => sub { my ($self) = @_; my $sql = super(); $sql .= sprintf "AND location = %d", $self->location; };

eewww, it's so stringy

I wonder if there is some way to do this with methods? DBIx::Class uses data structures to build SQL via SQL::Abstract and so the lack of methods there makes me wonder if there is a way to extend the query data structures in an OO-fashion

make a view my friend?

ORMesque has a different take on object-relational Perl - simply build database views for each thing you need. Why am I doing all this dynamic query extension in OO Perl anyway? An alterative approach would be to simply map my various program query requirements to database views.

I think it's interesting to explore how best to tread the line between programming languages and relational database engines. I suppose that using an ORM allows you to be more dynamic but I'm not sure.

recent threads

a recent thread shows resultset restriction but not extension. I'd be curious as to how to extend things with DBIx::Class... or your opinion on database views as an alternative approach.

living breathing code

I wrote DBIx::Cookbook to build up an executable comparison reference, so contributions there are welcome too.



The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"


In reply to DBIx::Class, make me drool by metaperl

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.