[Dbix-class] RFC: DBIx::Class 0.05 Schemas + Catalyst?
Brandon Black
blblack at gmail.com
Tue Jan 31 17:54:26 CET 2006
It seems to me that there should be a Catalyst::Model::DBIC::Schema,
which makes a $c->model('FooDB') for a given Schema + connection info.
Unlike the previous Catalyst::Model::DBIC, which only used ::Loader,
this Model should work for any Schema, whether it was a manual one, or
one defined by ::Schema::Loader. The Schema itself should be
elsewhere (not in the Catalyst Model/ directory. If you really want
it to be wrapped up in your Catalyst app, stick it in
lib/MyApp/Schema.pm or something).
I hacked up a Catalyst::Model::DBIC::Schema today and got it to appear
to work correctly. My model class ends up looking like:
-----------------------------------
package MyApp::M::MyDB;
use strict;
use base 'Catalyst::Model::DBIC::Schema';
__PACKAGE__->config(
schema_class => 'My::Schema',
dsn => 'dbi:Pg:dbname=mydb',
user => 'postgres',
password => '',
options => { AutoCommit => 1 },
);
1;
--------------------------------------
Where My::Schema isa DBIx::Class::Schema defined elsewhere outside the
model directory (like lib/My/Schema.pm). Note that this allows you to
have multiple $c->model('Foo'), $c->model('Bar'), etc, which use the
same Schema-class but different connection information.
My draft Catalyst::Model::DBIC::Schema is attached as an attachment.
The big problem with the approach I used to make this, is that all
access from within controllers turns into the idiom:
$c->model('MyDB')->schema->resultset('Foo')->search(...).
I'd really like to get the "->schema" step out of there, but I didn't
see any obvious (to me) way of getting the Catalyst Model instance to
simultaneously be both a Catalyst::Base and a schema object, so I just
put the schema object in a ->schema accessor.
Thoughts on all of this, anyone?
-- Brandon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Catalyst-Model-DBIC-Schema.pm
Type: application/x-perl
Size: 752 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060131/ca1c4867/Catalyst-Model-DBIC-Schema.bin
More information about the Dbix-class
mailing list