1 package DBIx::Class::Schema::Loader;
4 use UNIVERSAL::require;
10 DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
14 use DBIx::Class::Schema::Loader;
16 my $loader = DBIx::Class::Schema::Loader->new(
17 dsn => "dbi:mysql:dbname",
21 additional_classes => [qw/DBIx::Class::Foo/],
22 additional_base_classes => [qw/My::Stuff/],
23 left_base_classes => [qw/DBIx::Class::Bar/],
24 constraint => '^foo.*',
26 options => { AutoCommit => 1 },
27 inflect => { child => 'children' },
31 my $conn = $loader->connection($dsn, $user, $password); #
32 my $conn = $loader->connection(); # uses same dsn as ->new();
39 use DBIx::Class::Loader;
40 my $loader = DBIx::Class::Loader->new(
41 dsn => "dbi:mysql:dbname",
47 in your web application.
51 # you can use Data::Film directly
52 my $conn = $loader->connection();
53 my $film_moniker = $loader->moniker('film');
54 my $a_film = $conn->resultset($film_moniker)->find($id);
58 DBIx::Class::Schema::Loader automate the definition of a
59 DBIx::Class::Schema by scanning table schemas and setting up
60 columns and primary keys.
62 DBIx::Class::Schema::Loader supports MySQL, Postgres, SQLite and DB2. See
63 L<DBIx::Class::Schema::Loader::Generic> for more, and
64 L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
65 db-specific subclass for an unsupported db.
67 L<Class::DBI::Loader>, L<Class::DBI>, and L<DBIx::Class::Loader> are now
68 obsolete, use L<DBIx::Class> and this module instead. ;)
76 Example in Synopsis above demonstrates the available arguments. For
77 detailed information on the arguments, see the
78 L<DBIx::Class::Schema::Loader::Generic> documentation.
83 my ( $class, %args ) = @_;
85 foreach (qw/namespace dsn/) {
86 die qq/Argument $_ is required/ if ! $args{$_};
89 $args{namespace} =~ s/(.*)::$/$1/;
92 my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
93 $driver = 'SQLite' if $driver eq 'SQLite2';
94 my $impl = "DBIx::Class::Schema::Loader::" . $driver;
97 die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
99 return $impl->new(%args);
104 Sebastian Riedel, C<sri@oook.de>
106 Based upon the work of IKEBE Tomohiro
110 Adam Anderson, Andy Grundman, Autrijus Tang, Dan Kubb, David Naughton,
111 Randal Schwartz, Simon Flack and all the others who've helped.
115 This library is free software; you can redistribute it and/or modify it under
116 the same terms as Perl itself.