/[couchdb]/scripts/reblog2couchdb.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /scripts/reblog2couchdb.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Tue Aug 5 13:28:54 2008 UTC (15 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 1437 byte(s)
test import of items from reblog to couchdb
1 dpavlin 2 #!/usr/bin/perl -w
2    
3     use strict;
4     use DBI;
5     use CouchDB::Client;
6     use Data::Dump qw/dump/;
7    
8     $|++;
9    
10     my $database = 'reblog';
11    
12     my $connect = "DBI:mysql:database=$database";
13     #$connect = "DBI:mysql:database=$database;host=localhost;port=13306";
14    
15     my $dbh = DBI->connect($connect,"","") || die $DBI::errstr;
16    
17     # select all posts which have been read or unread
18     my $sql = qq{
19     select
20     *
21     from items
22     -- join items_userdata on id=item_id
23     -- where label = 'read' and value_numeric = ?
24     -- limit 3
25     order by id asc
26     };
27    
28     my $sth = $dbh->prepare($sql) || die $dbh->errstr();
29     $sth->execute( 1 ) || die $sth->errstr();
30    
31     print "found ",$sth->rows," items to process...";
32    
33     my $c = CouchDB::Client->new(uri => 'http://localhost:5984/');
34    
35     $c->testConnection or die "The server cannot be reached";
36     print "Running version " . $c->serverInfo->{version} . "\n";
37     my $db = $c->newDB( $database );
38     $db->create unless $c->dbExists( $database );
39    
40     my @docs = $db->listDocs;
41     my $row_id = shift @docs || 0;
42    
43     my $pk = 'id';
44    
45     while (my $row = $sth->fetchrow_hashref() ) {
46     my $_id = $row->{$pk};
47     my $doc = $db->newDoc( $_id );
48     $doc->{data} = $row;
49     eval { $doc->create };
50     if ( $@ ) {
51     warn "can't create $_id $@";
52     eval { $doc->update };
53     warn $@ ? "can't update $_id $@" : "updated $_id";
54     } else {
55     warn "created ",dump( $row );
56     }
57     }
58    
59     __END__
60    
61     $sql = qq{
62     update items_userdata
63     set value_numeric = 1
64     where label = 'read' and item_id in ($ids)
65     };
66    
67     $dbh->do( $sql );
68    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26