existing Schemas, but required if you use either of the C<create=>
options.
+username and password can be omitted for C<SQLite> dsns.
+
Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
=head1 TYPICAL EXAMPLES
- # Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
- # and a Model which references it:
+Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
+and a Model which references it:
+
script/myapp_create.pl model CatalystModelName DBIC::Schema \
MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass
- # Same, with extra connect_info args
+Same, with extra connect_info args
+user and pass can be omitted for sqlite, since they are always empty
+
script/myapp_create.pl model CatalystModelName DBIC::Schema \
- MyApp::SchemaClass create=static dbi:SQLite:foo.db '' '' \
+ MyApp::SchemaClass create=static dbi:SQLite:foo.db \
AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
- on_connect_do='["select 1", "select 2"]'
+ on_connect_do='["select 1", "select 2"]' quote_char='"'
+
+B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT>
+
+In C<cmd.exe> the above example would be:
+
+ script/myapp_create.pl model CatalystModelName DBIC::Schema \
+ MyApp::SchemaClass create=static dbi:SQLite:foo.db \
+ AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
+ on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""
+
+Same, but with extra Schema::Loader args (separate multiple values by commas):
- # Same, but with extra Schema::Loader args (separate multiple values by commas):
script/myapp_create.pl model CatalystModelName DBIC::Schema \
MyApp::SchemaClass create=static db_schema=foodb components=Foo,Bar \
- exclude='^wibble|wobble$' moniker_map='{ foo => "FFFFUUUU" }' \
+ exclude='^wibble|wobble$' moniker_map='{ foo => "FOO" }' \
dbi:Pg:dbname=foodb myuname mypass
- # See DBIx::Class::Schema::Loader::Base for list of options
+See L<DBIx::Class::Schema::Loader::Base> for a list of options
+
+Create a dynamic DBIx::Class::Schema::Loader-based Schema,
+and a Model which references it (B<DEPRECATED>):
- # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
- # and a Model which references it:
script/myapp_create.pl model CatalystModelName DBIC::Schema \
MyApp::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
- # Reference an existing Schema of any kind, and provide some connection information for ->config:
+Reference an existing Schema of any kind, and provide some connection information for ->config:
+
script/myapp_create.pl model CatalystModelName DBIC::Schema \
MyApp::SchemaClass dbi:mysql:foodb myuname mypass
- # Same, but don't supply connect information yet (you'll need to do this
- # in your app config, or [not recommended] in the schema itself).
+Same, but don't supply connect information yet (you'll need to do this
+in your app config, or [not recommended] in the schema itself).
+
script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass
=cut
my @connect_info = @$connect_info;
- my ($dsn, $user, $password) = splice @connect_info, 0, 3;
+ my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info);
tie my %helper_connect_info, 'Tie::IxHash';
return Data::Dumper->Dump([$data]);
}
+sub _get_dsn_user_pass {
+ my ($self, $connect_info) = @_;
+
+ my $dsn = shift @$connect_info;
+ my ($user, $password);
+
+ if ($dsn =~ /sqlite/i) {
+ ($user, $password) = ('', '');
+ shift @$connect_info while $connect_info->[0] eq '';
+ } else {
+ ($user, $password) = splice @$connect_info, 0, 2;
+ }
+
+ ($dsn, $user, $password)
+}
+
sub _parse_connect_info {
my ($self, $connect_info) = @_;
my @connect_info = @$connect_info;
- my ($dsn, $user, $password) = splice @connect_info, 0, 3;
+ my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info);
tie my %connect_info, 'Tie::IxHash';
@connect_info{qw/dsn user password/} = ($dsn, $user, $password);
=cut
1;
+__END__
+# vim:sts=4 sw=4:
my $test_params = [
[ 'TestSchema', 'DBIC::Schema', '' ],
[ 'TestSchemaDSN', 'DBIC::Schema', q{fakedsn fakeuser fakepass "{ AutoCommit => 1 }"} ],
+ [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static roles=Caching moniker_map="{ roles => \"ROLE\" }" constraint="^users\z" dbi:SQLite:testdb.db "" "" on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
+ [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static roles=Caching moniker_map="{ roles => \"ROLE\" }" dbi:SQLite:testdb.db on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
];
-plan tests => (2 * @$test_params);
+plan tests => (2 * @$test_params + 2);
my $test_dir = $FindBin::Bin;
my $blib_dir = File::Spec->catdir ($test_dir, '..', 'blib', 'lib');
my $cat_dir = File::Spec->catdir ($test_dir, 'TestApp');
my $catlib_dir = File::Spec->catdir ($cat_dir, 'lib');
+my $schema_dir = File::Spec->catdir ($catlib_dir, 'TestSchemaDSN');
my $creator = File::Spec->catfile($cat_dir, 'script', 'testapp_create.pl');
my $model_dir = File::Spec->catdir ($catlib_dir, 'TestApp', 'Model');
+my $db = File::Spec->catdir ($cat_dir, 'testdb.db');
chdir($test_dir);
system("catalyst.pl TestApp");
chdir($cat_dir);
+# create test db
+open my $sql, '|-', 'sqlite3', $db or die $!;
+print $sql <<'EOF';
+CREATE TABLE users (
+ id INTEGER PRIMARY KEY,
+ username TEXT,
+ password TEXT,
+ email_address TEXT,
+ first_name TEXT,
+ last_name TEXT,
+ active INTEGER
+);
+CREATE TABLE roles (
+ id INTEGER PRIMARY KEY,
+ role TEXT
+);
+EOF
+close $sql;
+
foreach my $tparam (@$test_params) {
my ($model, $helper, $args) = @$tparam;
system("$^X -I$blib_dir $creator model $model $helper $model $args");
ok( -f $model_path, "$model_path is a file" );
my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path");
ok($compile_rv == 0, "perl -c $model_path");
+
+ if ($args =~ /create=static/) {
+ my $glob = File::Spec->catfile($schema_dir, 'Result', '*');
+ my $tables =()= glob($glob);
+ if ($args =~ /constraint/) {
+ is $tables, 1, 'constraint works';
+ } else {
+ is $tables, 2, 'correct number of tables';
+ }
+ }
}
chdir($test_dir);