4 $ENV{DBI_AUTOPROXY}='dbi:Gofer:transport=stream;url=ssh:dpavlin@koha.ffzg.hr';
10 use Data::Dump qw/dump/;
14 my $debug = @ARGV ? 1 : 0;
16 our $dbi = "DBI:mysql:database=test";
17 our ( $dbi, $user, $password );
18 our ( $database, $collection ) = ( 'test', 'test' );
32 warn "# $dbi $user -> $database $collection\n";
34 my $conn = MongoDB::Connection->new;
35 my $db = $conn->get_database( $database );
36 my $coll = $db->get_collection( $collection );
37 my $dbh = DBI->connect($dbi,$user,$password,{ RaiseError => 1 });
41 # > db.items.find().sort({item_id:-1}).limit(1);
42 my $last = $coll->query()->sort({ '_id' => -1 })->limit(1)->next;
44 my $last_id = $last->{_id} || 0;
46 print "Fetching items from $dbi _id > $last_id\n";
48 my $sth = $dbh->prepare($sql);
49 $sth->execute( $last_id );
51 warn dump( $sth->{NAME} );
53 print "found ",$sth->rows," items to process...\n";
55 while (my $row = $sth->fetchrow_hashref() ) {
57 map { $row->{$_} * 1 } grep { defined $row->{$_} && $row->{$_} =~ /^\d+$/ } keys %$row;
58 $coll->insert( $row );