fix precedence error in Row->_is_column_numeric
[dbsrgits/DBIx-Class.git] / examples / Schema / insertdb.pl
CommitLineData
f54428ab 1#!/usr/bin/env perl
0c337847 2
0c337847 3use strict;
f54428ab 4use warnings;
5
6use MyDatabase::Main;
0c337847 7
8my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
9
10# here's some of the sql that is going to be generated by the schema
11# INSERT INTO artist VALUES (NULL,'Michael Jackson');
12# INSERT INTO artist VALUES (NULL,'Eminem');
13
14my @artists = (['Michael Jackson'], ['Eminem']);
15$schema->populate('Artist', [
16 [qw/name/],
17 @artists,
18]);
19
20my %albums = (
21 'Thriller' => 'Michael Jackson',
22 'Bad' => 'Michael Jackson',
23 'The Marshall Mathers LP' => 'Eminem',
24);
25
26my @cds;
27foreach my $lp (keys %albums) {
c6e27318 28 my $artist = $schema->resultset('Artist')->find({
0c337847 29 name => $albums{$lp}
30 });
c6e27318 31 push @cds, [$lp, $artist->id];
0c337847 32}
33
34$schema->populate('Cd', [
35 [qw/title artist/],
36 @cds,
37]);
38
39
40my %tracks = (
41 'Beat It' => 'Thriller',
42 'Billie Jean' => 'Thriller',
43 'Dirty Diana' => 'Bad',
44 'Smooth Criminal' => 'Bad',
45 'Leave Me Alone' => 'Bad',
46 'Stan' => 'The Marshall Mathers LP',
47 'The Way I Am' => 'The Marshall Mathers LP',
48);
49
50my @tracks;
51foreach my $track (keys %tracks) {
3d9632fd 52 my $cd = $schema->resultset('Cd')->find({
0c337847 53 title => $tracks{$track},
54 });
3d9632fd 55 push @tracks, [$cd->id, $track];
0c337847 56}
57
58$schema->populate('Track',[
59 [qw/cd title/],
60 @tracks,
61]);