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 that
110           extensions defined in files. By default errors from imported
111           modules are suppressed.  When you want to debug, use require_warn.
112
113       require_warn
114           Warn of import errors when requiring modules.
115

AUTHOR

117       Daisuke Maki "dmaki@cpan.org"
118

AUTHOR EMERITUS

120       Sebastian Riedel, "sri@oook.de" IKEBE Tomohiro, "ikebe@edge.co.jp"
121

THANK YOU

123       Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
124       Randal Schwartz, Simon Flack and all the others who've helped.
125

LICENSE

127       This library is free software; you can redistribute it and/or modify it
128       under the same terms as Perl itself.
129

SEE ALSO

131       Class::DBI, Class::DBI::mysql, Class::DBI::Pg, Class::DBI::SQLite,
132       Class::DBI::Loader::Generic, Class::DBI::Loader::mysql,
133       Class::DBI::Loader::Pg, Class::DBI::Loader::SQLite
134
135
136
137perl v5.34.0                      2021-07-22             Class::DBI::Loader(3)
Impressum