tests cleaned a little, added autoloading of on-disk class defs, added currently...
[dbsrgits/DBIx-Class-Schema-Loader.git] / README
1 NAME
2     DBIx::Class::Schema::Loader - Dynamic definition of a
3     DBIx::Class::Schema
4
5 SYNOPSIS
6       package My::Schema;
7       use base qw/DBIx::Class::Schema::Loader/;
8
9       __PACKAGE__->load_from_connection(
10         dsn                     => "dbi:mysql:dbname",
11         user                    => "root",
12         password                => "",
13         additional_classes      => [qw/DBIx::Class::Foo/],
14         additional_base_classes => [qw/My::Stuff/],
15         left_base_classes       => [qw/DBIx::Class::Bar/],
16         components              => [qw/ResultSetManager/],
17         resultset_components    => [qw/AlwaysRS/],
18         constraint              => '^foo.*',
19         relationships           => 1,
20         options                 => { AutoCommit => 1 }, 
21         inflect                 => { child => 'children' },
22         debug                   => 1,
23       );
24
25       # in seperate application code ...
26
27       use My::Schema;
28
29       my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
30       # -or-
31       my $schema1 = "My::Schema";
32       # ^^ defaults to dsn/user/pass from load_from_connection()
33
34       # Get a list of the original (database) names of the tables that
35       #  were loaded
36       my @tables = $schema1->loader->tables;
37
38       # Get a hashref of table_name => 'TableName' table-to-moniker
39       #   mappings.
40       my $monikers = $schema1->loader->monikers;
41
42       # Get a hashref of table_name => 'My::Schema::TableName'
43       #   table-to-classname mappings.
44       my $classes = $schema1->loader->classes;
45
46       # Use the schema as per normal for DBIx::Class::Schema
47       my $rs = $schema1->resultset($monikers->{foo_table})->search(...);
48
49 DESCRIPTION
50     DBIx::Class::Schema::Loader automates the definition of a
51     DBIx::Class::Schema by scanning table schemas and setting up columns and
52     primary keys.
53
54     DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2.
55     See DBIx::Class::Schema::Loader::Generic for more, and
56     DBIx::Class::Schema::Loader::Writing for notes on writing your own
57     db-specific subclass for an unsupported db.
58
59     This module requires DBIx::Class 0.05 or later, and obsoletes
60     DBIx::Class::Loader for DBIx::Class version 0.05 and later.
61
62     While on the whole, the bare table definitions are fairly
63     straightforward, relationship creation is somewhat heuristic, especially
64     in the choosing of relationship types, join types, and relationship
65     names. The relationships generated by this module will probably never be
66     as well-defined as hand-generated ones. Because of this, over time a
67     complex project will probably wish to migrate off of
68     DBIx::Class::Schema::Loader.
69
70     It is designed more to get you up and running quickly against an
71     existing database, or to be effective for simple situations, rather than
72     to be what you use in the long term for a complex database/project.
73
74     That being said, transitioning your code from a Schema generated by this
75     module to one that doesn't use this module should be straightforward and
76     painless, so don't shy away from it just for fears of the transition
77     down the road.
78
79 METHODS
80   load_from_connection
81     Example in Synopsis above demonstrates the available arguments. For
82     detailed information on the arguments, see the
83     DBIx::Class::Schema::Loader::Generic documentation.
84
85   loader
86     This is an accessor in the generated Schema class for accessing the
87     DBIx::Class::Schema::Loader::Generic -based loader object that was used
88     during construction. See the DBIx::Class::Schema::Loader::Generic docs
89     for more information on the available loader methods there.
90
91 KNOWN BUGS
92     Aside from relationship definitions being less than ideal in general,
93     this version is known not to handle the case of multiple relationships
94     between the same pair of tables. All of the relationship code will be
95     overhauled on the way to 0.03, at which time that bug will be addressed.
96
97 AUTHOR
98     Brandon Black, "blblack@gmail.com"
99
100     Based on DBIx::Class::Loader by Sebastian Riedel
101
102     Based upon the work of IKEBE Tomohiro
103
104 THANK YOU
105     Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
106     Randal Schwartz, Simon Flack and all the others who've helped.
107
108 LICENSE
109     This library is free software; you can redistribute it and/or modify it
110     under the same terms as Perl itself.
111
112 SEE ALSO
113     DBIx::Class
114