Streamline ::ResultSource::* inheritance, similar to d009cb7d
[dbsrgits/DBIx-Class-Historic.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;
e48635f7 7use DBIx::Class::_Util 'parent_dir';
0c337847 8
e48635f7 9my $db_fn = parent_dir( $INC{'MyApp/Schema.pm'} ) . '../db/example.db';
15ff1933 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', [
1f9ae1a3 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',[
1f9ae1a3 58 [qw/cdid title/],
0c337847 59 @tracks,
60]);