Examples and documentation update and cleanup
[dbsrgits/DBIx-Class.git] / examples / Schema / insertdb.pl
old mode 100644 (file)
new mode 100755 (executable)
index e8603bb..ae919b3
@@ -1,13 +1,14 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
 
-use MyDatabase::Main;
 use strict;
+use warnings;
 
-my $schema = MyDatabase::Main->connect('dbi:SQLite:db/example.db');
+use MyApp::Schema;
 
-#  here's some of the sql that is going to be generated by the schema
-#  INSERT INTO artist VALUES (NULL,'Michael Jackson');
-#  INSERT INTO artist VALUES (NULL,'Eminem');
+use Path::Class 'file';
+my $db_fn = file($INC{'MyApp/Schema.pm'})->dir->parent->file('db/example.db');
+
+my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn");
 
 my @artists = (['Michael Jackson'], ['Eminem']);
 $schema->populate('Artist', [
@@ -30,7 +31,7 @@ foreach my $lp (keys %albums) {
 }
 
 $schema->populate('Cd', [
-    [qw/title artist/],
+    [qw/title artistid/],
     @cds,
 ]);
 
@@ -47,13 +48,13 @@ my %tracks = (
 
 my @tracks;
 foreach my $track (keys %tracks) {
-    my $cdname = $schema->resultset('Cd')->search({
+    my $cd = $schema->resultset('Cd')->find({
         title => $tracks{$track},
     });
-    push @tracks, [$cdname->first, $track];
+    push @tracks, [$cd->id, $track];
 }
 
 $schema->populate('Track',[
-    [qw/cd title/],
+    [qw/cdid title/],
     @tracks,
 ]);