[Dbix-class] Schema stuff [WAS: RFC: DBIx::Class 0.05 Schemas + Catalyst?]

Brandon Black blblack at gmail.com
Wed Feb 1 06:10:34 CET 2006


On 1/31/06, Alan Humphrey <alan.humphrey at comcast.net> wrote:
> Brandon asked:
>
> How are you doing it now, without a Catalyst::Model::DBIC-like thing,
> and still getting at various schema objects from all of your
> controllers?
>
>
> Here's what I'm doing.  I'll start general and get into code later.  If
> anyone sees better ways to accomplish the job, please chime in.  This
> discussion is based on DBIx-Class 0.04001.
>
> [..........]

That makes sense.  I don't know how to work around the NoBindStorage
thing eloquently yet, but I haven't really put much thought into that
yet either.

Attached is yet another (probably alpha-quality at best) redux of a
proposed Catalyst::Model::DBIC::Schema, based on irc this evening.

This one is much better about seperating things out so that at some
future time when Cat itself supports it, you can have multiple Cat app
instances using the same Schema and Model classes with different
configured connection info under the same mod_perl, and also properly
supports resultset shortcuts.

Assuming a My::Schema exists somewhere in @INC, Model classes end up
looking like:

------------------------------------------
package MyApp::M::MyApp;
use strict;
use base qw/Catalyst::Model::DBIC::Schema/;

__PACKAGE__->config(
    schema_class => 'My::Schema',
    connect_info => [
        'dbi:Pg:dbname=modeltest',
        'postgres',
        '',
        { AutoCommit => 1},
    ],
);

1;
-------------------------

And controller access to various things ends up like:

# to access arbitrary schema methods
$c->model('MyApp')->schema->xxx

# to access a composed schema namespace which has no connection
defined (ideal for making new connections on the fly):
my $newconn = $c->model('MyApp')->composed_schema->connect(...);

# to access resultsets the hard way:
$c->model('MyApp')->schema->resultset('Foo')->xxx;

# the easy way that does the same thing:
$c->model('MyApp::Foo')->xxx;
# for use like:
my $rs = $c->model('MyApp::Foo')->search();

It relies on recent unreleased changes in the DBIx::Class and Catalyst
trunks at the moment, but those should make it to a release soon.

-- Brandon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: C-M-DBIC-Schema.pm
Type: application/octet-stream
Size: 3989 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060131/923b1a24/C-M-DBIC-Schema.obj


More information about the Dbix-class mailing list