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