Created
August 23, 2012 13:36
-
-
Save dch/3436658 to your computer and use it in GitHub Desktop.
load docs from files using Store::CouchDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Store::CouchDB; | |
use JSON; | |
use File::Slurp; | |
# unbuffer output to line up stderr/stdout | |
$|=1; | |
# my $parser = JSON->new->use_utf8->decode; | |
my $couch = Store::CouchDB->new(); | |
$couch->config({host => 'localhost', | |
port => '5984', | |
user => 'admin', | |
pass => 'passwd', | |
db => 'yourdb'}); | |
# processing sample output | |
# my $doc = $couch->get_doc({id => 'master'}); | |
# say JSON->new->pretty->utf8->encode($doc); | |
# read filenames from argv | |
while (my $json = shift @ARGV) { | |
chomp $json; | |
my ($data, $doc); | |
say "[$json]"; | |
$data = read_file $json | |
or die "$! unable to read $json\n"; | |
say "reading...OK"; | |
$doc = decode_json $data | |
or die "$! unable to parse $json\n"; | |
say "parsing...OK"; | |
$couch->put_doc({doc => $doc}) | |
or die "$! unable to PUT $json\n"; | |
say "storing...OK"; | |
} | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment