forked from manwar/Dancer2-Cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_database.pl
34 lines (27 loc) · 946 Bytes
/
populate_database.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
33
34
package My::Bookstore::Schema;
use DBIx::Class::Schema::Loader;
use base qw(DBIx::Class::Schema::Loader);
package main;
my $schema = My::Bookstore::Schema->connect('dbi:SQLite:dbname=bookstore.db');
$schema->populate(
'Author', [
['firstname', 'lastname'],
['Ian M.', 'Banks' ],
['Richard', 'Matheson'],
['Frank', 'Herbert' ],
]);
my @books_list = (
['Consider Phlebas', 'Banks' ],
['The Player of Games', 'Banks' ],
['Use of Weapons', 'Banks' ],
['Dune', 'Herbert' ],
['Dune Messiah', 'Herbert' ],
['Children of Dune', 'Herbert' ],
['The Night Stalker', 'Matheson'],
['The Night Strangler', 'Matheson'],
);
# transform author names into ids
foreach (@books_list) {
$_->[1] = $schema->resultset('Author')->find({ lastname => $_->[1] })->id;
}
$schema->populate('Book', [['title', 'author'], @books_list ]);