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, $user, $password ) = ( "DBI:mysql:database=test" );
17 our ( $database, $collection ) = ( 'test', 'test' );
18 our ( $table, $pk ) = ( 'items', 'id' );
22 warn "# $dbi $user -> $database $collection\n";
24 my $conn = MongoDB::Connection->new;
25 my $db = $conn->get_database( $database );
26 my $coll = $db->get_collection( $collection );
27 my $dbh = DBI->connect($dbi,$user,$password, {
29 # mysql_enable_utf8 => 1,
34 # db.items.find().sort({_id:-1}).limit(1);
35 my $last = $coll->query()->sort({ '_id' => -1 })->limit(1)->next;
37 my $last_id = $last->{_id} || 0;
39 print "Fetching items from $dbi _id > $last_id\n";
41 my $sth = $dbh->prepare(qq{
51 $sth->execute( $last_id );
53 warn dump( $sth->{NAME} );
55 print "found ",$sth->rows," items to process...\n";
57 while (my $row = $sth->fetchrow_hashref() ) {
59 map { $row->{$_} * 1 } grep { defined $row->{$_} && $row->{$_} =~ /^\d+$/ } keys %$row;
60 $coll->insert( $row );