1Class::DBI::Loader(3) User Contributed Perl DocumentationClass::DBI::Loader(3)
2
3
4

NAME

6       Class::DBI::Loader - Dynamic definition of Class::DBI sub classes.
7

SYNOPSIS

9         use Class::DBI::Loader;
10
11         my $loader = Class::DBI::Loader->new(
12           dsn                     => "dbi:mysql:dbname",
13           user                    => "root",
14           password                => "",
15           options                 => { RaiseError => 1, AutoCommit => 0 },
16           namespace               => "Data",
17           additional_classes      => qw/Class::DBI::AbstractSearch/, # or arrayref
18           additional_base_classes => qw/My::Stuff/, # or arrayref
19           left_base_classes       => qw/Class::DBI::Sweet/, # or arrayref
20           constraint              => '^foo.*',
21           relationships           => 1,
22           options                 => { AutoCommit => 1 },
23           inflect                 => { child => 'children' },
24           require                 => 1
25         );
26         my $class = $loader->find_class('film'); # $class => Data::Film
27         my $obj = $class->retrieve(1);
28
29       use with mod_perl
30
31       in your startup.pl
32
33         # load all tables
34         use Class::DBI::Loader;
35         my $loader = Class::DBI::Loader->new(
36           dsn       => "dbi:mysql:dbname",
37           user      => "root",
38           password  => "",
39           namespace => "Data",
40         );
41
42       in your web application.
43
44         use strict;
45
46         # you can use Data::Film directly
47         my $film = Data::Film->retrieve($id);
48

DESCRIPTION

50       Class::DBI::Loader automate the definition of Class::DBI sub-classes.
51       scan table schemas and setup columns, primary key.
52
53       class names are defined by table names and namespace option.
54
55        +-----------+-----------+-----------+
56        |   table   | namespace | class     |
57        +-----------+-----------+-----------+
58        |   foo     | Data      | Data::Foo |
59        |   foo_bar |           | FooBar    |
60        +-----------+-----------+-----------+
61
62       Class::DBI::Loader supports MySQL, Postgres and SQLite.
63
64       See Class::DBI::Loader::Generic.
65

METHODS

67   new %args
68       additional_base_classes
69           List of additional base classes your table classes will use.
70
71       left_base_classes
72           List of additional base classes, that need to be leftmost, for
73           example Class::DBI::Sweet (former Catalyst::Model::CDBI::Sweet).
74
75       additional_classes
76           List of additional classes which your table classes will use.
77
78       constraint
79           Only load tables matching regex.
80
81       exclude
82           Exclude tables matching regex.
83
84       debug
85           Enable debug messages.
86
87       dsn DBI Data Source Name.
88
89       namespace
90           Namespace under which your table classes will be initialized.
91
92       password
93           Password.
94
95       options
96           Optional hashref to specify DBI connect options
97
98       relationships
99           Try to automatically detect/setup has_a and has_many relationships.
100
101       inflect
102           An hashref, which contains exceptions to Lingua::EN::Inflect::PL().
103           Useful for foreign language column names.
104
105       user
106           Username.
107
108       require
109           Attempt to require the dynamically defined module, so