First, create some dirs and change working directory:
- mkdir DB
- mkdir DB/Main
+ mkdir MyDatabase
+ mkdir MyDatabase/Main
Then, create the following DBIx::Class::Schema classes:
-DB/Main.pm:
+MyDatabase/Main.pm:
- package DB::Main;
+ package MyDatabase::Main;
use base qw/DBIx::Class::Schema/;
__PACKAGE__->load_classes(qw/Artist Cd Track/);
1;
-DB/Main/Artist.pm:
+MyDatabase/Main/Artist.pm:
- package DB::Main::Artist;
+ package MyDatabase::Main::Artist;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
- __PACKAGE__->has_many('cds' => 'DB::Main::Cd');
+ __PACKAGE__->has_many('cds' => 'MyDatabase::Main::Cd');
1;
-DB/Main/Cd.pm:
+MyDatabase/Main/Cd.pm:
- package DB::Main::Cd;
+ package MyDatabase::Main::Cd;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('cd');
__PACKAGE__->add_columns(qw/ cdid artist title/);
__PACKAGE__->set_primary_key('cdid');
- __PACKAGE__->belongs_to('artist' => 'DB::Main::Artist');
- __PACKAGE__->has_many('tracks' => 'DB::Main::Track');
+ __PACKAGE__->belongs_to('artist' => 'MyDatabase::Main::Artist');
+ __PACKAGE__->has_many('tracks' => 'MyDatabase::Main::Track');
1;
-DB/Main/Track.pm:
+MyDatabase/Main/Track.pm:
- package DB::Main::Track;
+ package MyDatabase::Main::Track;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('track');
__PACKAGE__->add_columns(qw/ trackid cd title/);
__PACKAGE__->set_primary_key('trackid');
- __PACKAGE__->belongs_to('cd' => 'DB::Main::Cd');
+ __PACKAGE__->belongs_to('cd' => 'MyDatabase::Main::Cd');
1;
#!/usr/bin/perl -w
- use DB::Main;
+ use MyDatabase::Main;
use strict;
- my $schema = DB::Main->connect('dbi:SQLite:example.db');
+ my $schema = MyDatabase::Main->connect('dbi:SQLite:example.db');
# here's some of the sql that is going to be generated by the schema
# INSERT INTO artist VALUES (NULL,'Michael Jackson');
#!/usr/bin/perl -w
- use DB::Main;
+ use MyDatabase::Main;
use strict;
- my $schema = DB::Main->connect('dbi:SQLite:example.db');
+ my $schema = MyDatabase::Main->connect('dbi:SQLite:example.db');
get_tracks_by_cd('Bad');
get_tracks_by_artist('Michael Jackson');
=head1 Notes
With these scripts we're relying on @INC looking in the current
-working directory. You may want to add the DB namespaces to @INC in a
-different way when it comes to deployemnt.
+working directory. You may want to add the MyDatabase namespaces to
+@INC in a different way when it comes to deployemnt.
The testdb.pl script is an excellent start for testing your database
model.