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