schema-loader does multi-column FKs now, needs a bit of cleanup/refactor work
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader.pm
CommitLineData
18fca96a 1package DBIx::Class::Schema::Loader;
a78e3fed 2
3use strict;
a4a19f3c 4use warnings;
5
6use vars qw($VERSION @ISA);
a78e3fed 7use UNIVERSAL::require;
8
a4a19f3c 9# Always remember to do all digits for the version even if they're 0
10# i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
11# brain damage and presumably various other packaging systems too
12
13$VERSION = '0.01000';
a78e3fed 14
15=head1 NAME
16
18fca96a 17DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
a78e3fed 18
19=head1 SYNOPSIS
20
a4a19f3c 21 package My::Schema;
22 use base qw/DBIx::Class::Schema::Loader/;
a78e3fed 23
a4a19f3c 24 __PACKAGE__->load_from_connection(
a78e3fed 25 dsn => "dbi:mysql:dbname",
26 user => "root",
27 password => "",
a78e3fed 28 additional_classes => [qw/DBIx::Class::Foo/],
29 additional_base_classes => [qw/My::Stuff/],
30 left_base_classes => [qw/DBIx::Class::Bar/],
31 constraint => '^foo.*',
32 relationships => 1,
33 options => { AutoCommit => 1 },
34 inflect => { child => 'children' },
35 debug => 1,
36 );
af6c2665 37
a4a19f3c 38 # in seperate application code ...
a78e3fed 39
a4a19f3c 40 use My::Schema;
a78e3fed 41
a4a19f3c 42 my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
43 # -or-
fbd83464 44 my $schema1 = "My::Schema";
a4a19f3c 45 # ^^ defaults to dsn/user/pass from load_from_connection()
a78e3fed 46
47=head1 DESCRIPTION
48
fbd83464 49DBIx::Class::Schema::Loader automates the definition of a
18fca96a 50DBIx::Class::Schema by scanning table schemas and setting up
51columns and primary keys.
a78e3fed 52
18fca96a 53DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. See
54L<DBIx::Class::Schema::Loader::Generic> for more, and
55L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
56db-specific subclass for an unsupported db.
a78e3fed 57
fbd83464 58This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
59and later.
a78e3fed 60
61=cut
62
63=head1 METHODS
64
fbd83464 65=head2 load_from_connection
a78e3fed 66
67Example in Synopsis above demonstrates the available arguments. For
68detailed information on the arguments, see the
18fca96a 69L<DBIx::Class::Schema::Loader::Generic> documentation.
a78e3fed 70
71=cut
72
a4a19f3c 73sub load_from_connection {
a78e3fed 74 my ( $class, %args ) = @_;
af6c2665 75
fbd83464 76 die qq/dsn argument is required/ if ! $args{dsn};
af6c2665 77
a78e3fed 78 my $dsn = $args{dsn};
79 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
80 $driver = 'SQLite' if $driver eq 'SQLite2';
18fca96a 81 my $impl = "DBIx::Class::Schema::Loader::" . $driver;
af6c2665 82
a78e3fed 83 $impl->require or
fbd83464 84 die qq/Couldn't require loader class "$impl",/ .
85 qq/"$UNIVERSAL::require::ERROR"/;
af6c2665 86
a4a19f3c 87 push(@ISA, $impl);
88 $class->_load_from_connection(%args);
a78e3fed 89}
90
91=head1 AUTHOR
92
fbd83464 93Brandon Black, C<bblack@gmail.com>
94
95Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
a78e3fed 96
97Based upon the work of IKEBE Tomohiro
98
99=head1 THANK YOU
100
101Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
102Randal Schwartz, Simon Flack and all the others who've helped.
103
104=head1 LICENSE
105
106This library is free software; you can redistribute it and/or modify it under
107the same terms as Perl itself.
108
109=head1 SEE ALSO
110
111L<DBIx::Class>
112
113=cut
114
1151;