-#!/usr/bin/perl -w
+#!/usr/bin/env perl
-use MyDatabase::Main;
+use warnings;
use strict;
-my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+use MyApp::Schema;
+
+use Path::Class 'file';
+my $db_fn = file($INC{'MyApp/Schema.pm'})->dir->parent->file('db/example.db');
+
# for other DSNs, e.g. MySql, see the perldoc for the relevant dbd
# driver, e.g perldoc L<DBD::mysql>.
+my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn");
get_tracks_by_cd('Bad');
get_tracks_by_artist('Michael Jackson');
},
{
join => [qw/ cd /],
- prefetch => [qw/ cd /]
}
);
while (my $track = $rs->next) {
}
);
while (my $track = $rs->next) {
- print $track->title . "\n";
+ print $track->title . " (from the CD '" . $track->cd->title
+ . "')\n";
}
print "\n";
}
-
sub get_cd_by_track {
my $tracktitle = shift;
print "get_cd_by_track($tracktitle):\n";
}
);
my $cd = $rs->first;
- print $cd->title . "\n\n";
+ print $cd->title . " has the track '$tracktitle'.\n\n";
}
sub get_cds_by_artist {
},
{
join => [qw/ artist /],
- prefetch => [qw/ artist /]
}
);
while (my $cd = $rs->next) {
print "\n";
}
-
-
sub get_artist_by_track {
my $tracktitle = shift;
print "get_artist_by_track($tracktitle):\n";
}
);
my $artist = $rs->first;
- print $artist->name . "\n\n";
+ print $artist->name . " recorded the track '$tracktitle'.\n\n";
}
-
sub get_artist_by_cd {
my $cdtitle = shift;
print "get_artist_by_cd($cdtitle):\n";
}
);
my $artist = $rs->first;
- print $artist->name . "\n\n";
+ print $artist->name . " recorded the CD '$cdtitle'.\n\n";
}