more work on extended set of Pg auto-pk tests
[dbsrgits/DBIx-Class.git] / examples / Schema / insertdb.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
8# here's some of the sql that is going to be generated by the schema
9# INSERT INTO artist VALUES (NULL,'Michael Jackson');
10# INSERT INTO artist VALUES (NULL,'Eminem');
11
12my @artists = (['Michael Jackson'], ['Eminem']);
13$schema->populate('Artist', [
14 [qw/name/],
15 @artists,
16]);
17
18my %albums = (
19 'Thriller' => 'Michael Jackson',
20 'Bad' => 'Michael Jackson',
21 'The Marshall Mathers LP' => 'Eminem',
22);
23
24my @cds;
25foreach my $lp (keys %albums) {
26 my $artist = $schema->resultset('Artist')->search({
27 name => $albums{$lp}
28 });
29 push @cds, [$lp, $artist->first];
30}
31
32$schema->populate('Cd', [
33 [qw/title artist/],
34 @cds,
35]);
36
37
38my %tracks = (
39 'Beat It' => 'Thriller',
40 'Billie Jean' => 'Thriller',
41 'Dirty Diana' => 'Bad',
42 'Smooth Criminal' => 'Bad',
43 'Leave Me Alone' => 'Bad',
44 'Stan' => 'The Marshall Mathers LP',
45 'The Way I Am' => 'The Marshall Mathers LP',
46);
47
48my @tracks;
49foreach my $track (keys %tracks) {
50 my $cdname = $schema->resultset('Cd')->search({
51 title => $tracks{$track},
52 });
53 push @tracks, [$cdname->first, $track];
54}
55
56$schema->populate('Track',[
57 [qw/cd title/],
58 @tracks,
59]);