forked from dnorman/perl-DBR
/
example_insert.pl
executable file
·32 lines (22 loc) · 1.02 KB
/
example_insert.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
use strict;
use lib qw'lib ../lib ../../lib';
####### Provision the sandbox DB, for examples/testing only ###########
use DBR::Sandbox( schema => 'music', writeconf => 'generated_dbr.conf', reuse => 1 );
#######################################################################
# Here is the real code:
use DBR ( conf => 'generated_dbr.conf', logpath => 'dbr_example.log', loglevel => 'debug3', use_exceptions => 1 );
my $music = dbr_connect('music'); # dbr_connect is imported into your scope when you 'use DBR (...)'
my $artists = $music->artist->all;
print "Artists:\n\n";
while (my $artist = $artists->next){
print $artist->name . "\n";
while ( my $album = $artist->albums->next ){
print "\tAlbum " . $album->name . "\n";
my $track_id = $music->track->insert(
album_id => $album->album_id,
name => 'Track ' . int(rand(100000)),
) or die "failed to insert";
print "\t\tinserted track_id $track_id\n";
}
}