Documentation improvements cherry-picked from latest
[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
15ff1933 8use Path::Class 'file';
9my $db_fn = file($INC{'MyApp/Schema.pm'})->dir->parent->file('db/example.db');
10
11my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn");
0c337847 12
0c337847 13my @artists = (['Michael Jackson'], ['Eminem']);
14$schema->populate('Artist', [
15 [qw/name/],
16 @artists,
17]);
18
19my %albums = (
20 'Thriller' => 'Michael Jackson',
21 'Bad' => 'Michael Jackson',
22 'The Marshall Mathers LP' => 'Eminem',
23);
24
25my @cds;
26foreach my $lp (keys %albums) {
c6e27318 27 my $artist = $schema->resultset('Artist')->find({
0c337847 28 name => $albums{$lp}
29 });
c6e27318 30 push @cds, [$lp, $artist->id];
0c337847 31}
32
33$schema->populate('Cd', [
60fbfe7d 34 [qw/title artistid/],
0c337847 35 @cds,
36]);
37
38
39my %tracks = (
40 'Beat It' => 'Thriller',
41 'Billie Jean' => 'Thriller',
42 'Dirty Diana' => 'Bad',
43 'Smooth Criminal' => 'Bad',
44 'Leave Me Alone' => 'Bad',
45 'Stan' => 'The Marshall Mathers LP',
46 'The Way I Am' => 'The Marshall Mathers LP',
47);
48
49my @tracks;
50foreach my $track (keys %tracks) {
3d9632fd 51 my $cd = $schema->resultset('Cd')->find({
0c337847 52 title => $tracks{$track},
53 });
3d9632fd 54 push @tracks, [$cd->id, $track];
0c337847 55}
56
57$schema->populate('Track',[
60fbfe7d 58 [qw/cdid title/],
0c337847 59 @tracks,
60]);