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.