These comments are woefully outdated
[dbsrgits/DBIx-Class.git] / examples / Schema / insertdb.pl
CommitLineData
f54428ab 1#!/usr/bin/env perl
0c337847 2
0c337847 3use strict;
f54428ab 4use warnings;
5
a5bd5d88 6use MyApp::Schema;
0c337847 7
a5bd5d88 8my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db');
0c337847 9
0c337847 10my @artists = (['Michael Jackson'], ['Eminem']);
11$schema->populate('Artist', [
12 [qw/name/],
13 @artists,
14]);
15
16my %albums = (
17 'Thriller' => 'Michael Jackson',
18 'Bad' => 'Michael Jackson',
19 'The Marshall Mathers LP' => 'Eminem',
20);
21
22my @cds;
23foreach my $lp (keys %albums) {
c6e27318 24 my $artist = $schema->resultset('Artist')->find({
0c337847 25 name => $albums{$lp}
26 });
c6e27318 27 push @cds, [$lp, $artist->id];
0c337847 28}
29
30$schema->populate('Cd', [
31 [qw/title artist/],
32 @cds,
33]);
34
35
36my %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
46my @tracks;
47foreach my $track (keys %tracks) {
3d9632fd 48 my $cd = $schema->resultset('Cd')->find({
0c337847 49 title => $tracks{$track},
50 });
3d9632fd 51 push @tracks, [$cd->id, $track];
0c337847 52}
53
54$schema->populate('Track',[
55 [qw/cd title/],
56 @tracks,
57]);