[Dbix-class] DBIx::Class::Schema added

Matt S Trout dbix-class at trout.me.uk
Thu Aug 4 19:17:24 CEST 2005


Possibly the single most annoying thing about working with Class::DBI is
having your database connection turn up via inheritance so you end up
having to do some fairly nasty things to pick one per runtime. So, enter
DBIx::Class::Schema -

in My/Schema.pm:

 package My::Schema;

 use base qw/DBIx::Class::Schema/;

 __PACKAGE__->load_classes(qw/Foo Bar Baz/);

in My/Schema/Foo.pm:

 package My::Schema::Foo;

 use base qw/DBIx::Class::Core/;

 __PACKAGE__->table('foo');
 ...

in My/DB.pm (note no package My::DB - this is auto-created by the Schema):

 use My::Schema;

 My::Schema->compose_connection('My::DB', $dsn, $user, $pass, $attrs);

 then in app code

my @obj = My::DB::Foo->retrieve_all; # My::DB::Foo isa My::Schema::Foo My::DB 

But, equally, if you have a dynamic app, you can do the compose_connection
yourself - it's all the same to the code :)

-- 
     Matt S Trout           Website: http://www.shadowcatsystems.co.uk
  Technical Director        E-mail:  mst (at) shadowcatsystems.co.uk
Shadowcat Systems Ltd.



More information about the Dbix-class mailing list