This hack is superseded by theorbtwo's POD::Inherit (which however has problems on...
[dbsrgits/DBIx-Class.git] / examples / Schema / testdb.pl
CommitLineData
0c337847 1#!/usr/bin/perl -w
2
3use MyDatabase::Main;
4use strict;
5
6my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
7# for other DSNs, e.g. MySql, see the perldoc for the relevant dbd
8# driver, e.g perldoc L<DBD::mysql>.
9
10get_tracks_by_cd('Bad');
11get_tracks_by_artist('Michael Jackson');
12
13get_cd_by_track('Stan');
14get_cds_by_artist('Michael Jackson');
15
16get_artist_by_track('Dirty Diana');
17get_artist_by_cd('The Marshall Mathers LP');
18
19
20sub get_tracks_by_cd {
21 my $cdtitle = shift;
22 print "get_tracks_by_cd($cdtitle):\n";
23 my $rs = $schema->resultset('Track')->search(
24 {
25 'cd.title' => $cdtitle
26 },
27 {
28 join => [qw/ cd /],
0c337847 29 }
30 );
31 while (my $track = $rs->next) {
32 print $track->title . "\n";
33 }
34 print "\n";
35}
36
37sub get_tracks_by_artist {
38 my $artistname = shift;
39 print "get_tracks_by_artist($artistname):\n";
40 my $rs = $schema->resultset('Track')->search(
41 {
42 'artist.name' => $artistname
43 },
44 {
45 join => {
46 'cd' => 'artist'
47 },
48 }
49 );
50 while (my $track = $rs->next) {
51 print $track->title . "\n";
52 }
53 print "\n";
54}
55
56
57sub get_cd_by_track {
58 my $tracktitle = shift;
59 print "get_cd_by_track($tracktitle):\n";
60 my $rs = $schema->resultset('Cd')->search(
61 {
62 'tracks.title' => $tracktitle
63 },
64 {
65 join => [qw/ tracks /],
66 }
67 );
68 my $cd = $rs->first;
69 print $cd->title . "\n\n";
70}
71
72sub get_cds_by_artist {
73 my $artistname = shift;
74 print "get_cds_by_artist($artistname):\n";
75 my $rs = $schema->resultset('Cd')->search(
76 {
77 'artist.name' => $artistname
78 },
79 {
80 join => [qw/ artist /],
0c337847 81 }
82 );
83 while (my $cd = $rs->next) {
84 print $cd->title . "\n";
85 }
86 print "\n";
87}
88
89
90
91sub get_artist_by_track {
92 my $tracktitle = shift;
93 print "get_artist_by_track($tracktitle):\n";
94 my $rs = $schema->resultset('Artist')->search(
95 {
96 'tracks.title' => $tracktitle
97 },
98 {
99 join => {
100 'cds' => 'tracks'
101 }
102 }
103 );
104 my $artist = $rs->first;
105 print $artist->name . "\n\n";
106}
107
108
109sub get_artist_by_cd {
110 my $cdtitle = shift;
111 print "get_artist_by_cd($cdtitle):\n";
112 my $rs = $schema->resultset('Artist')->search(
113 {
114 'cds.title' => $cdtitle
115 },
116 {
117 join => [qw/ cds /],
118 }
119 );
120 my $artist = $rs->first;
121 print $artist->name . "\n\n";
122}