Class::DBI::Loader - Dynamic definition of Class::DBI sub classes. |
Class::DBI::Loader - Dynamic definition of Class::DBI sub classes.
use Class::DBI::Loader;
my $loader = Class::DBI::Loader->new( dsn => "dbi:mysql:dbname", user => "root", password => "", options => { RaiseError => 1, AutoCommit => 0 }, namespace => "Data", additional_classes => qw/Class::DBI::AbstractSearch/, # or arrayref additional_base_classes => qw/My::Stuff/, # or arrayref left_base_classes => qw/Class::DBI::Sweet/, # or arrayref constraint => '^foo.*', relationships => 1, options => { AutoCommit => 1 }, inflect => { child => 'children' }, require => 1 ); my $class = $loader->find_class('film'); # $class => Data::Film my $obj = $class->retrieve(1);
use with mod_perl
in your startup.pl
# load all tables use Class::DBI::Loader; my $loader = Class::DBI::Loader->new( dsn => "dbi:mysql:dbname", user => "root", password => "", namespace => "Data", );
in your web application.
use strict;
# you can use Data::Film directly my $film = Data::Film->retrieve($id);
Class::DBI::Loader automate the definition of Class::DBI sub-classes. scan table schemas and setup columns, primary key.
class names are defined by table names and namespace option.
+-----------+-----------+-----------+ | table | namespace | class | +-----------+-----------+-----------+ | foo | Data | Data::Foo | | foo_bar | | FooBar | +-----------+-----------+-----------+
Class::DBI::Loader supports MySQL, Postgres and SQLite.
See the Class::DBI::Loader::Generic manpage.
Daisuke Maki dmaki@cpan.org
Sebastian Riedel, sri@oook.de
IKEBE Tomohiro, ikebe@edge.co.jp
Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton, Randal Schwartz, Simon Flack and all the others who've helped.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
the Class::DBI manpage, the Class::DBI::mysql manpage, the Class::DBI::Pg manpage, the Class::DBI::SQLite manpage, the Class::DBI::Loader::Generic manpage, the Class::DBI::Loader::mysql manpage, the Class::DBI::Loader::Pg manpage, the Class::DBI::Loader::SQLite manpage
Class::DBI::Loader - Dynamic definition of Class::DBI sub classes. |