1 package DBIx::Class::Schema::Loader;
5 use base qw/DBIx::Class::Schema/;
6 use base qw/Class::Data::Accessor/;
8 use UNIVERSAL::require;
10 # Always remember to do all digits for the version even if they're 0
11 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports
12 # brain damage and presumably various other packaging systems too
13 our $VERSION = '0.01003';
15 __PACKAGE__->mk_classaccessor('loader');
19 DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
24 use base qw/DBIx::Class::Schema::Loader/;
26 __PACKAGE__->load_from_connection(
27 dsn => "dbi:mysql:dbname",
30 additional_classes => [qw/DBIx::Class::Foo/],
31 additional_base_classes => [qw/My::Stuff/],
32 left_base_classes => [qw/DBIx::Class::Bar/],
33 constraint => '^foo.*',
35 options => { AutoCommit => 1 },
36 inflect => { child => 'children' },
40 # in seperate application code ...
44 my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
46 my $schema1 = "My::Schema";
47 # ^^ defaults to dsn/user/pass from load_from_connection()
49 # Get a list of the original (database) names of the tables that
51 my @tables = $schema1->loader->tables;
53 # Get a hashref of table_name => 'TableName' table-to-moniker
55 my $monikers = $schema1->loader->monikers;
57 # Get a hashref of table_name => 'My::Schema::TableName'
58 # table-to-classname mappings.
59 my $classes = $schema1->loader->classes;
61 # Use the schema as per normal for DBIx::Class::Schema
62 my $rs = $schema1->resultset($monikers->{table_table})->search(...);
66 THIS IS A DEVELOPMENT RELEASE. This is 0.01xxx, the first public
67 releases. Expect things to be broken in various ways. Expect the
68 entire design to be fatally flawed. Expect the interfaces to change if
69 it becomes neccessary. It's mostly here for people to poke at it and
70 find the flaws in it. 0.02 will hopefully have some sanity when we get
73 DBIx::Class::Schema::Loader automates the definition of a
74 DBIx::Class::Schema by scanning table schemas and setting up
75 columns and primary keys.
77 DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. See
78 L<DBIx::Class::Schema::Loader::Generic> for more, and
79 L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
80 db-specific subclass for an unsupported db.
82 This module requires L<DBIx::Class> 0.05 or later, and obsoletes
83 L<DBIx::Class::Loader> for L<DBIx::Class> version 0.05 and later.
87 =head2 load_from_connection
89 Example in Synopsis above demonstrates the available arguments. For
90 detailed information on the arguments, see the
91 L<DBIx::Class::Schema::Loader::Generic> documentation.
95 sub load_from_connection {
96 my ( $class, %args ) = @_;
98 croak 'dsn argument is required' if ! $args{dsn};
100 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
101 $driver = 'SQLite' if $driver eq 'SQLite2';
102 my $impl = "DBIx::Class::Schema::Loader::" . $driver;
105 croak qq/Couldn't require loader class "$impl",/ .
106 qq/"$UNIVERSAL::require::ERROR"/;
108 $args{schema} = $class;
110 $class->loader($impl->new(%args));
111 $class->loader->load;
116 This is an accessor in the generated Schema class for accessing
117 the L<DBIx::Class::Schema::Loader::Generic> -based loader object
118 that was used during construction. See the
119 L<DBIx::Class::Schema::Loader::Generic> docs for more information
120 on the available loader methods there.
124 Brandon Black, C<blblack@gmail.com>
126 Based on L<DBIx::Class::Loader> by Sebastian Riedel
128 Based upon the work of IKEBE Tomohiro
132 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
133 Randal Schwartz, Simon Flack and all the others who've helped.
137 This library is free software; you can redistribute it and/or modify it under
138 the same terms as Perl itself.