AnyEvent-CouchDB

 view release on metacpan or  search on metacpan

bin/couchdb-push  view on Meta::CPAN

use File::Basename;
use IO::All;
use JSON;
use URI::Escape;
use MIME::Base64;

my $__help     = undef;
my $__verbose  = undef;
my $__force    = undef;
my $__user     = undef;
my $__password = undef;

GetOptions(
  "help|h"       => \$__help,
  "verbose|v"    => \$__verbose,
  "force|f"      => \$__force,
  "user|u=s"     => \$__user,
  "password|p=s" => \$__password,
);

my $json = JSON->new;

if ($__help || @ARGV == 0) {
my $executable = basename $0;
print qq{couchdb-push - push documents from the filesystem to CouchDB

Usage:

  $executable [OPTION]... <FILE>... <COUCHDB_DATABASE>

Options:

  -h, --help            This help message
  -v, --verbose         Verbose output
  -u, --user            user
  -p, --password        password
  -f, --force           Overwrite documents that already exist

};
exit 0;
}

my $name = pop;
my $db   = couchdb($name);

print "db: " . $db->uri . "\n" if ($__verbose);

my $options;
if ($__user && $__password) {
  $options->{headers}->{Authentication} = "Basic ".encode_base64($__user.':'.$__password,'');
}

for (@ARGV) {
  my $file;
  my $doc;
  eval {
    $file = io($_);
    $doc  = $json->decode(scalar $file->all);
  };
  if ($@) {

lib/AnyEvent/CouchDB.pm  view on Meta::CPAN

  print pp( $couch->info->recv    ), "\n";

Get an object representing a CouchDB database:

  my $db = $couch->db('database');
  $db    = couchdb('database');
  $db    = couchdb('http://somewhere.com:7777/database/');

With authentication:

  # user is the username and s3cret is the password
  $db = couchdb('http://user:s3cret@somewhere.com:7777/database');

Work with individual CouchDB documents;

  my $user = $db->open_doc('~larry')->recv;
  $user->{name} = "larry";
  $db->save_doc($user)->recv;

Query a view:

lib/AnyEvent/CouchDB/Database.pm  view on Meta::CPAN

key, wich will be added to all the requests. So you can add basic
authentication to your requests if needed:

  my $couchdb = couch("http://127.0.0.1:5984/");
  my $db      = $couchdb->db("mydb");
  my $auth    = encode_base64('user:s3kr3t', '');

  my $res = $db->create({headers => {'Authorization' => 'Basic '.$aut}})->recv;

B<UPDATE>:  You can now make authenticated requests by placing the username and
password in the URI.

  my $db = couchdb('http://user:s3kr3t@127.0.0.1:5984/mydb');

=head2 Database Level Operations

=head3 $cv = $db->create([ \%options ])

This method is used to create a CouchDB database.  It returns an L<AnyEvent>
condvar.



( run in 0.472 second using v1.01-cache-2.11-cpan-49f99fa48dc )