These comments are woefully outdated
[dbsrgits/DBIx-Class-Historic.git] / examples / Schema / insertdb.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use MyApp::Schema;
7
8 my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
9
10 my @artists = (['Michael Jackson'], ['Eminem']);
11 $schema->populate('Artist', [
12     [qw/name/],
13     @artists,
14 ]);
15
16 my %albums = (
17     'Thriller' => 'Michael Jackson',
18     'Bad' => 'Michael Jackson',
19     'The Marshall Mathers LP' => 'Eminem',
20 );
21
22 my @cds;
23 foreach my $lp (keys %albums) {
24     my $artist = $schema->resultset('Artist')->find({
25         name => $albums{$lp}
26     });
27     push @cds, [$lp, $artist->id];
28 }
29
30 $schema->populate('Cd', [
31     [qw/title artist/],
32     @cds,
33 ]);
34
35
36 my %tracks = (
37     'Beat It'         => 'Thriller',
38     'Billie Jean'     => 'Thriller',
39     'Dirty Diana'     => 'Bad',
40     'Smooth Criminal' => 'Bad',
41     'Leave Me Alone'  => 'Bad',
42     'Stan'            => 'The Marshall Mathers LP',
43     'The Way I Am'    => 'The Marshall Mathers LP',
44 );
45
46 my @tracks;
47 foreach my $track (keys %tracks) {
48     my $cd = $schema->resultset('Cd')->find({
49         title => $tracks{$track},
50     });
51     push @tracks, [$cd->id, $track];
52 }
53
54 $schema->populate('Track',[
55     [qw/cd title/],
56     @tracks,
57 ]);