From: Peter Rabbitson Date: Mon, 26 Aug 2013 01:57:42 +0000 (+0200) Subject: Standardize examples/docs on Schema::Loader schema naming X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a5bd5d88980681e140bc910d0cd38dd21db48218;p=dbsrgits%2FDBIx-Class-Historic.git Standardize examples/docs on Schema::Loader schema naming A new user is very likely to encounter this naming convention these days --- diff --git a/examples/Schema/MyDatabase/Main.pm b/examples/Schema/MyApp/Schema.pm similarity index 78% rename from examples/Schema/MyDatabase/Main.pm rename to examples/Schema/MyApp/Schema.pm index 6217cac..3642e82 100644 --- a/examples/Schema/MyDatabase/Main.pm +++ b/examples/Schema/MyApp/Schema.pm @@ -1,4 +1,4 @@ -package MyDatabase::Main; +package MyApp::Schema; use warnings; use strict; diff --git a/examples/Schema/MyDatabase/Main/Result/Artist.pm b/examples/Schema/MyApp/Schema/Result/Artist.pm similarity index 63% rename from examples/Schema/MyDatabase/Main/Result/Artist.pm rename to examples/Schema/MyApp/Schema/Result/Artist.pm index 0571dae..61a11f2 100644 --- a/examples/Schema/MyDatabase/Main/Result/Artist.pm +++ b/examples/Schema/MyApp/Schema/Result/Artist.pm @@ -1,4 +1,4 @@ -package MyDatabase::Main::Result::Artist; +package MyApp::Schema::Result::Artist; use warnings; use strict; @@ -11,7 +11,7 @@ __PACKAGE__->add_columns(qw/ artistid name /); __PACKAGE__->set_primary_key('artistid'); -__PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd'); +__PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd'); 1; diff --git a/examples/Schema/MyDatabase/Main/Result/Cd.pm b/examples/Schema/MyApp/Schema/Result/Cd.pm similarity index 50% rename from examples/Schema/MyDatabase/Main/Result/Cd.pm rename to examples/Schema/MyApp/Schema/Result/Cd.pm index 9dc1f4e..6d600a1 100644 --- a/examples/Schema/MyDatabase/Main/Result/Cd.pm +++ b/examples/Schema/MyApp/Schema/Result/Cd.pm @@ -1,4 +1,4 @@ -package MyDatabase::Main::Result::Cd; +package MyApp::Schema::Result::Cd; use warnings; use strict; @@ -11,7 +11,7 @@ __PACKAGE__->add_columns(qw/ cdid artist title year /); __PACKAGE__->set_primary_key('cdid'); -__PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist'); -__PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track'); +__PACKAGE__->belongs_to('artist' => 'MyApp::Schema::Result::Artist'); +__PACKAGE__->has_many('tracks' => 'MyApp::Schema::Result::Track'); 1; diff --git a/examples/Schema/MyDatabase/Main/Result/Track.pm b/examples/Schema/MyApp/Schema/Result/Track.pm similarity index 63% rename from examples/Schema/MyDatabase/Main/Result/Track.pm rename to examples/Schema/MyApp/Schema/Result/Track.pm index 961018b..91b8368 100644 --- a/examples/Schema/MyDatabase/Main/Result/Track.pm +++ b/examples/Schema/MyApp/Schema/Result/Track.pm @@ -1,4 +1,4 @@ -package MyDatabase::Main::Result::Track; +package MyApp::Schema::Result::Track; use warnings; use strict; @@ -11,6 +11,6 @@ __PACKAGE__->add_columns(qw/ trackid cd title/); __PACKAGE__->set_primary_key('trackid'); -__PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd'); +__PACKAGE__->belongs_to('cd' => 'MyApp::Schema::Result::Cd'); 1; diff --git a/examples/Schema/insertdb.pl b/examples/Schema/insertdb.pl old mode 100644 new mode 100755 index a701795..15bf71b --- a/examples/Schema/insertdb.pl +++ b/examples/Schema/insertdb.pl @@ -3,9 +3,9 @@ use strict; use warnings; -use MyDatabase::Main; +use MyApp::Schema; -my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); +my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); # here's some of the sql that is going to be generated by the schema # INSERT INTO artist VALUES (NULL,'Michael Jackson'); diff --git a/examples/Schema/testdb.pl b/examples/Schema/testdb.pl old mode 100644 new mode 100755 index a65db0f..3d057fd --- a/examples/Schema/testdb.pl +++ b/examples/Schema/testdb.pl @@ -3,9 +3,9 @@ use warnings; use strict; -use MyDatabase::Main; +use MyApp::Schema; -my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); +my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); # for other DSNs, e.g. MySql, see the perldoc for the relevant dbd # driver, e.g perldoc L. diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 80ae5d0..36b891e 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -1163,14 +1163,14 @@ as each other and your connecting database user has the proper permissions to th To accomplish this one only needs to specify the DB schema name in the table declaration, like so... - package MyDatabase::Main::Artist; + package MyApp::Schema::Result::Artist; use base qw/DBIx::Class::Core/; __PACKAGE__->table('database1.artist'); # will use "database1.artist" in FROM clause __PACKAGE__->add_columns(qw/ artist_id name /); __PACKAGE__->set_primary_key('artist_id'); - __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd'); + __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd'); 1; @@ -1186,7 +1186,7 @@ However, one can dynamically "map" to the proper DB schema by overriding the L method in your Schema class and building a renaming facility, like so: - package MyDatabase::Schema; + package MyApp::Schema; use Moose; extends 'DBIx::Class::Schema'; @@ -1232,7 +1232,7 @@ To use this facility, simply add or modify the \%attr hashref that is passed to L, as follows: my $schema - = MyDatabase::Schema->connect( + = MyApp::Schema->connect( $dsn, $user, $pass, diff --git a/lib/DBIx/Class/Manual/Example.pod b/lib/DBIx/Class/Manual/Example.pod index 2d0e2e3..e41945b 100644 --- a/lib/DBIx/Class/Manual/Example.pod +++ b/lib/DBIx/Class/Manual/Example.pod @@ -70,56 +70,56 @@ Change directory back from db to the directory app: Now create some more directories: - mkdir MyDatabase - mkdir MyDatabase/Main - mkdir MyDatabase/Main/Result - mkdir MyDatabase/Main/ResultSet + mkdir MyApp + mkdir MyApp/Schema + mkdir MyApp/Schema/Result + mkdir MyApp/Schema/ResultSet Then, create the following DBIx::Class::Schema classes: -MyDatabase/Main.pm: +MyApp/Schema.pm: - package MyDatabase::Main; + package MyApp::Schema; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_namespaces; 1; -MyDatabase/Main/Result/Artist.pm: +MyApp/Schema/Result/Artist.pm: - package MyDatabase::Main::Result::Artist; + package MyApp::Schema::Result::Artist; use base qw/DBIx::Class::Core/; __PACKAGE__->table('artist'); __PACKAGE__->add_columns(qw/ artistid name /); __PACKAGE__->set_primary_key('artistid'); - __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Result::Cd'); + __PACKAGE__->has_many('cds' => 'MyApp::Schema::Result::Cd'); 1; -MyDatabase/Main/Result/Cd.pm: +MyApp/Schema/Result/Cd.pm: - package MyDatabase::Main::Result::Cd; + package MyApp::Schema::Result::Cd; use base qw/DBIx::Class::Core/; __PACKAGE__->load_components(qw/InflateColumn::DateTime/); __PACKAGE__->table('cd'); __PACKAGE__->add_columns(qw/ cdid artist title/); __PACKAGE__->set_primary_key('cdid'); - __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Result::Artist'); - __PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Result::Track'); + __PACKAGE__->belongs_to('artist' => 'MyApp::Schema::Result::Artist'); + __PACKAGE__->has_many('tracks' => 'MyApp::Schema::Result::Track'); 1; -MyDatabase/Main/Result/Track.pm: +MyApp/Schema/Result/Track.pm: - package MyDatabase::Main::Result::Track; + package MyApp::Schema::Result::Track; use base qw/DBIx::Class::Core/; __PACKAGE__->table('track'); __PACKAGE__->add_columns(qw/ trackid cd title /); __PACKAGE__->set_primary_key('trackid'); - __PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Result::Cd'); + __PACKAGE__->belongs_to('cd' => 'MyApp::Schema::Result::Cd'); 1; @@ -133,9 +133,9 @@ insertdb.pl use strict; use warnings; - use MyDatabase::Main; + use MyApp::Schema; - my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); + my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); # here's some of the SQL that is going to be generated by the schema # INSERT INTO artist VALUES (NULL,'Michael Jackson'); @@ -199,9 +199,9 @@ testdb.pl: use strict; use warnings; - use MyDatabase::Main; + use MyApp::Schema; - my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); + my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); # for other DSNs, e.g. MySQL, see the perldoc for the relevant dbd # driver, e.g perldoc L. @@ -354,15 +354,15 @@ are available in the main distribution for DBIx::Class under the directory F. With these scripts we're relying on @INC looking in the current -working directory. You may want to add the MyDatabase namespaces to +working directory. You may want to add the MyApp namespaces to @INC in a different way when it comes to deployment. The F script is an excellent start for testing your database model. This example uses L to load in the -appropriate L classes from the MyDatabase::Main::Result namespace, -and any required resultset classes from the MyDatabase::Main::ResultSet +appropriate L classes from the MyApp::Schema::Result namespace, +and any required resultset classes from the MyApp::Schema::ResultSet namespace (although we created the directory in the directions above we did not add, or need to add, any resultset classes). diff --git a/lib/DBIx/Class/Manual/Intro.pod b/lib/DBIx/Class/Manual/Intro.pod index 1360782..f13e14e 100644 --- a/lib/DBIx/Class/Manual/Intro.pod +++ b/lib/DBIx/Class/Manual/Intro.pod @@ -209,7 +209,7 @@ If you have a mixed-case database, use the C option, e.g.: If you are using L, then you can use the helper that comes with L: - $ script/myapp_create.pl model MyDB DBIC::Schema MyDB::Schema \ + $ script/myapp_create.pl model MyModel DBIC::Schema MyApp::Schema \ create=static moniker_map='{ foo => "FOO" }' dbi:SQLite:./myapp.db \ on_connect_do='PRAGMA foreign_keys=ON' quote_char='"' diff --git a/lib/DBIx/Class/Manual/QuickStart.pod b/lib/DBIx/Class/Manual/QuickStart.pod index c589111..9f401f4 100644 --- a/lib/DBIx/Class/Manual/QuickStart.pod +++ b/lib/DBIx/Class/Manual/QuickStart.pod @@ -33,8 +33,8 @@ Inspect the database: You can also use a GUI database browser such as L. -Have a look at the schema classes files in the subdirectory F. The -C class is the entry point for loading the other classes and +Have a look at the schema classes files in the subdirectory F. The +C class is the entry point for loading the other classes and interacting with the database through DBIC and the C classes correspond to the tables in the database. L shows how to write all that Perl code. That is almost never necessary, though. Instead use @@ -46,8 +46,8 @@ chapter L below shows an example invocation. A L object represents the database. - use MyDatabase::Main qw(); - my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db'); + use MyApp::Schema qw(); + my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); The first four arguments are the same as for L. @@ -114,7 +114,7 @@ Set up a condition. } ); -Iterate over result objects of class C. +Iterate over result objects of class C. L objects represent a row and automatically get accessors for their column names. @@ -175,11 +175,11 @@ From a detail to the root: DBIx-Class/examples/Schema$ perl ./insertdb.pl # delete the schema classes files - DBIx-Class/examples/Schema$ rm -rf MyDatabase/ + DBIx-Class/examples/Schema$ rm -rf MyApp # recreate schema classes files from database file DBIx-Class/examples/Schema$ dbicdump \ - -o dump_directory=. MyDatabase::Main dbi:SQLite:db/example.db + -o dump_directory=. MyApp::Schema dbi:SQLite:db/example.db =head2 Where to go next diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 1df1005..16a0878 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -73,12 +73,13 @@ particular which module inherits off which. =back + package MyApp::Schema; __PACKAGE__->load_namespaces(); __PACKAGE__->load_namespaces( result_namespace => 'Res', resultset_namespace => 'RSet', - default_resultset_class => '+MyDB::Othernamespace::RSet', + default_resultset_class => '+MyApp::Othernamespace::RSet', ); With no arguments, this method uses L to load all of the diff --git a/lib/DBIx/Class/Storage/DBI/mysql.pm b/lib/DBIx/Class/Storage/DBI/mysql.pm index a2aa2fc..83ee8b2 100644 --- a/lib/DBIx/Class/Storage/DBI/mysql.pm +++ b/lib/DBIx/Class/Storage/DBI/mysql.pm @@ -176,7 +176,7 @@ DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifi Storage::DBI autodetects the underlying MySQL database, and re-blesses the C<$storage> object into this class. - my $schema = MyDb::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } ); + my $schema = MyApp::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } ); =head1 DESCRIPTION