1DBIx::Class::Schema::LoUasdeerr(C3o)ntributed Perl DocumDeBnItxa:t:iColnass::Schema::Loader(3)
2
3
4

NAME

6       DBIx::Class::Schema::Loader - Create a DBIx::Class::Schema based on a
7       database
8

SYNOPSIS

10           ### use this module to generate a set of class files
11
12           # in a script
13           use DBIx::Class::Schema::Loader qw/ make_schema_at /;
14           make_schema_at(
15               'My::Schema',
16               { debug => 1,
17                 dump_directory => './lib',
18               },
19               [ 'dbi:Pg:dbname="foo"', 'myuser', 'mypassword',
20                  { loader_class => 'MyLoader' } # optionally
21               ],
22           );
23
24           # from the command line or a shell script with dbicdump (distributed
25           # with this module).  Do `perldoc dbicdump` for usage.
26           dbicdump -o dump_directory=./lib \
27                    -o components='["InflateColumn::DateTime"]' \
28                    -o debug=1 \
29                    My::Schema \
30                    'dbi:Pg:dbname=foo' \
31                    myuser \
32                    mypassword
33
34           ### or generate and load classes at runtime
35           # note: this technique is not recommended
36           # for use in production code
37
38           package My::Schema;
39           use base qw/DBIx::Class::Schema::Loader/;
40
41           __PACKAGE__->loader_options(
42               constraint              => '^foo.*',
43               # debug                 => 1,
44           );
45
46           #### in application code elsewhere:
47
48           use My::Schema;
49
50           my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
51           # -or-
52           my $schema1 = "My::Schema"; $schema1->connection(as above);
53

DESCRIPTION

55       DBIx::Class::Schema::Loader automates the definition of a
56       DBIx::Class::Schema by scanning database table definitions and setting
57       up the columns, primary keys, unique constraints and relationships.
58
59       See dbicdump for the "dbicdump" utility.
60
61       DBIx::Class::Schema::Loader currently supports only the DBI storage
62       type. It has explicit support for DBD::Pg, DBD::mysql, DBD::DB2,
63       DBD::Firebird, DBD::InterBase, DBD::Informix, DBD::SQLAnywhere,
64       DBD::SQLite, DBD::Sybase (for Sybase ASE and MSSSQL), DBD::ODBC (for
65       MSSQL, MSAccess, Firebird and SQL Anywhere) DBD::ADO (for MSSQL and
66       MSAccess) and DBD::Oracle.  Other DBI drivers may function to a greater
67       or lesser degree with this loader, depending on how much of the DBI
68       spec they implement, and how standard their implementation is.
69
70       Patches to make other DBDs work correctly welcome.
71
72       See DBIx::Class::Schema::Loader::DBI::Writing for notes on writing your
73       own vendor-specific subclass for an unsupported DBD driver.
74
75       This module requires DBIx::Class 0.08127 or later, and obsoletes the
76       older DBIx::Class::Loader.
77
78       See DBIx::Class::Schema::Loader::Base for available options.
79

METHODS

81   loader
82       The loader object, as class data on your Schema. For methods available
83       see DBIx::Class::Schema::Loader::Base and
84       DBIx::Class::Schema::Loader::DBI.
85
86   loader_class
87       Argument: $loader_class
88
89       Set the loader class to be instantiated when "connection" is called.
90       If the classname starts with "::", "DBIx::Class::Schema::Loader" is
91       prepended. Defaults to "storage_type" in DBIx::Class::Schema (which
92       must start with "::" when using DBIx::Class::Schema::Loader).
93
94       This is mostly useful for subclassing existing loaders or in
95       conjunction with "dump_to_dir".
96
97   loader_options
98       Argument: \%loader_options
99
100       Example in Synopsis above demonstrates a few common arguments.  For
101       detailed information on all of the arguments, most of which are only
102       useful in fairly complex scenarios, see the
103       DBIx::Class::Schema::Loader::Base documentation.
104
105       If you intend to use "loader_options", you must call "loader_options"
106       before any connection is made, or embed the "loader_options" in the
107       connection information itself as shown below.  Setting "loader_options"
108       after the connection has already been made is useless.
109
110   connection
111       Arguments: @args
112       Return Value: $new_schema
113
114       See "connection" in DBIx::Class::Schema for basic usage.
115
116       If the final argument is a hashref, and it contains the keys
117       "loader_options" or "loader_class", those keys will be deleted, and
118       their values value will be used for the loader options or class,
119       respectively, just as if set via the "loader_options" or "loader_class"
120       methods above.
121
122       The actual auto-loading operation (the heart of this module) will be
123       invoked as soon as the connection information is defined.
124
125   clone
126       See "clone" in DBIx::Class::Schema.
127
128   dump_to_dir
129       Argument: $directory
130
131       Calling this as a class method on either DBIx::Class::Schema::Loader or
132       any derived schema class will cause all schemas to dump manual versions
133       of themselves to the named directory when they are loaded.  In order to
134       be effective, this must be set before defining a connection on this
135       schema class or any derived object (as the loading happens as soon as
136       both a connection and loader_options are set, and only once per class).
137
138       See "dump_directory" in DBIx::Class::Schema::Loader::Base for more
139       details on the dumping mechanism.
140
141       This can also be set at module import time via the import option
142       "dump_to_dir:/foo/bar" to DBIx::Class::Schema::Loader, where "/foo/bar"
143       is the target directory.
144
145       Examples:
146
147           # My::Schema isa DBIx::Class::Schema::Loader, and has connection info
148           #   hardcoded in the class itself:
149           perl -MDBIx::Class::Schema::Loader=dump_to_dir:/foo/bar -MMy::Schema -e1
150
151           # Same, but no hard-coded connection, so we must provide one:
152           perl -MDBIx::Class::Schema::Loader=dump_to_dir:/foo/bar -MMy::Schema -e 'My::Schema->connection("dbi:Pg:dbname=foo", ...)'
153
154           # Or as a class method, as long as you get it done *before* defining a
155           #  connection on this schema class or any derived object:
156           use My::Schema;
157           My::Schema->dump_to_dir('/foo/bar');
158           My::Schema->connection(........);
159
160           # Or as a class method on the DBIx::Class::Schema::Loader itself, which affects all
161           #   derived schemas
162           use My::Schema;
163           use My::OtherSchema;
164           DBIx::Class::Schema::Loader->dump_to_dir('/foo/bar');
165           My::Schema->connection(.......);
166           My::OtherSchema->connection(.......);
167
168           # Another alternative to the above:
169           use DBIx::Class::Schema::Loader qw| dump_to_dir:/foo/bar |;
170           use My::Schema;
171           use My::OtherSchema;
172           My::Schema->connection(.......);
173           My::OtherSchema->connection(.......);
174
175   make_schema_at
176       Arguments: $schema_class_name, \%loader_options, \@connect_info
177       Return Value: $schema_class_name
178
179       This function creates a DBIx::Class schema from an existing RDBMS
180       schema.  With the "dump_directory" option, generates a set of
181       DBIx::Class classes from an existing database schema read from the
182       given dsn.  Without a "dump_directory", creates schema classes in
183       memory at runtime without generating on-disk class files.
184
185       For a complete list of supported loader_options, see
186       DBIx::Class::Schema::Loader::Base
187
188       The last hashref in the "\@connect_info" can specify the
189       "loader_class".
190
191       This function can be imported in the usual way, as illustrated in these
192       Examples:
193
194           # Simple example, creates as a new class 'New::Schema::Name' in
195           #  memory in the running perl interpreter.
196           use DBIx::Class::Schema::Loader qw/ make_schema_at /;
197           make_schema_at(
198               'New::Schema::Name',
199               { debug => 1 },
200               [ 'dbi:Pg:dbname="foo"','postgres','',
201                 { loader_class => 'MyLoader' } # optionally
202               ],
203           );
204
205           # Inside a script, specifying a dump directory in which to write
206           # class files
207           use DBIx::Class::Schema::Loader qw/ make_schema_at /;
208           make_schema_at(
209               'New::Schema::Name',
210               { debug => 1, dump_directory => './lib' },
211               [ 'dbi:Pg:dbname="foo"','postgres','',
212                 { loader_class => 'MyLoader' } # optionally
213               ],
214           );
215
216       The last hashref in the "\@connect_info" is checked for loader
217       arguments such as "loader_options" and "loader_class", see "connection"
218       for more details.
219
220   rescan
221       Return Value: @new_monikers
222
223       Re-scans the database for newly added tables since the initial load,
224       and adds them to the schema at runtime, including relationships, etc.
225       Does not process drops or changes.
226
227       Returns a list of the new monikers added.
228
229   naming
230       Arguments: \%opts | $ver
231
232       Controls the naming options for backward compatibility, see "naming" in
233       DBIx::Class::Schema::Loader::Base for details.
234
235       To upgrade a dynamic schema, use:
236
237           __PACKAGE__->naming('current');
238
239       Can be imported into your dump script and called as a function as well:
240
241           naming('v4');
242
243   use_namespaces
244       Arguments: 1|0
245
246       Controls the use_namespaces options for backward compatibility, see
247       "use_namespaces" in DBIx::Class::Schema::Loader::Base for details.
248
249       To upgrade a dynamic schema, use:
250
251           __PACKAGE__->use_namespaces(1);
252
253       Can be imported into your dump script and called as a function as well:
254
255           use_namespaces(1);
256

KNOWN ISSUES

258   Multiple Database Schemas
259       See "db_schema" in DBIx::Class::Schema::Loader::Base.
260

ACKNOWLEDGEMENTS

262       Matt S Trout, all of the #dbix-class folks, and everyone who's ever
263       sent in a bug report or suggestion.
264
265       Based on DBIx::Class::Loader by Sebastian Riedel
266
267       Based upon the work of IKEBE Tomohiro
268

AUTHORS

270       Caelum: Rafael Kitover <rkitover@cpan.org>
271
272       Dag-Erling Smørgrav <des@des.no>
273
274       Matias E. Fernandez <mfernandez@pisco.ch>
275
276       SineSwiper: Brendan Byrd <byrd.b@insightcom.com>
277
278       TSUNODA Kazuya <drk@drk7.jp>
279
280       acmoore: Andrew Moore <amoore@cpan.org>
281
282       alnewkirk: Al Newkirk <awncorp@cpan.org>
283
284       andrewalker: André Walker <andre@andrewalker.net>
285
286       angelixd: Paul C. Mantz <pcmantz@cpan.org>
287
288       arc: Aaron Crane <arc@cpan.org>
289
290       arcanez: Justin Hunter <justin.d.hunter@gmail.com>
291
292       ash: Ash Berlin <ash@cpan.org>
293
294       blblack: Brandon Black <blblack@gmail.com>
295
296       bphillips: Brian Phillips <bphillips@cpan.org>
297
298       btilly: Ben Tilly <btilly@gmail.com>
299
300       domm: Thomas Klausner <domm@plix.at>
301
302       ether: Karen Etheridge <ether@cpan.org>
303
304       gugu: Andrey Kostenko <a.kostenko@rambler-co.ru>
305
306       hobbs: Andrew Rodland <arodland@cpan.org>
307
308       ilmari: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
309
310       jhannah: Jay Hannah <jay@jays.net>
311
312       jnap: John Napiorkowski <jjn1056@yahoo.com>
313
314       kane: Jos Boumans <kane@cpan.org>
315
316       mattp: Matt Phillips <mattp@cpan.org>
317
318       mephinet: Philipp Gortan <philipp.gortan@apa.at>
319
320       moritz: Moritz Lenz <moritz@faui2k3.org>
321
322       mst: Matt S. Trout <mst@shadowcatsystems.co.uk>
323
324       mstratman: Mark A. Stratman <stratman@gmail.com>
325
326       oalders: Olaf Alders <olaf@wundersolutions.com>
327
328       rbo: Robert Bohne <rbo@cpan.org>
329
330       rbuels: Robert Buels <rbuels@gmail.com>
331
332       ribasushi: Peter Rabbitson <ribasushi@cpan.org>
333
334       schwern: Michael G. Schwern <mschwern@cpan.org>
335
336       spb: Stephen Bennett <spb@exherbo.org>
337
338       timbunce: Tim Bunce <timb@cpan.org>
339
340       waawaamilk: Nigel McNie <nigel@mcnie.name>
341
342       ... and lots of other folks. If we forgot you, please write the current
343       maintainer or RT.
344
346       Copyright (c) 2006 - 2015 by the aforementioned "AUTHORS" in
347       DBIx::Class::Schema::Loader.
348
349       This library is free software; you can redistribute it and/or modify it
350       under the same terms as Perl itself.
351

SEE ALSO

353       DBIx::Class, DBIx::Class::Manual::Intro, DBIx::Class::Tutorial,
354       DBIx::Class::Schema::Loader::Base
355
356
357
358perl v5.38.0                      2023-07-20    DBIx::Class::Schema::Loader(3)
Impressum