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