This package has been deprecated

Author message:

no longer maintained

couch-replicator-api

0.0.0 • Public • Published

node-couch-replicator-api

Build Status

A simple Node API for dealing with the couch _replicator database

NPM

You can fetch status for a database replication, get a replication doc, delete a replication doc, and put a replication doc.

Example

const CouchReplicator = require('couch-replicator-api')
    , couchUrl        = 'http://npm.nodejs.org.au:5984'
    , couchUser       = 'admin'
    , couchPass       = 'super$ecure'
    , db              = 'registry'

CouchReplicator.status(couchUrl, couchUser, couchPass, db, printStatus)

// also:
//  - CouchReplicator.get(url, user, pass, db, callback)
//  - CouchReplicator.del(url, user, pass, db, [rev, ] callback)
//  - CouchReplicator.put(url, user, pass, db, doc, callback)

function printStatus (err, data) {
  if (err)
  
    throw err

  console.log('status:', data)
}

Will print the replication status:

status: { pid: '<0.26018.0>',
  checkpointed_source_seq: 93275,
  continuous: true,
  doc_id: 'registry',
  doc_write_failures: 0,
  docs_read: 450,
  docs_written: 450,
  missing_revisions_found: 450,
  progress: 98,
  replication_id: 'cb249c0a32a9c3c289c29efbea91fd92+continuous',
  revisions_checked: 533,
  source: 'https://fullfatdb.npmjs.com/registry/',
  source_seq: 94787,
  started_on: 1391948768,
  target: 'registry',
  type: 'replication',
  updated_on: 1392021201 }

Alternatively you can use the CouchReplicator as a constructor and store the Couch URL, admin credentials and database id in the object to make calls even simpler:

const CouchReplicator = require('couch-replicator-api')

    , replicator = new CouchReplicator(
          'http://npm.nodejs.org.au:5984'
        , 'admin'
        , 'super$ecure'
        , 'registry'
      )

replicator.status(function (err, data) {
  if (err)
  
    throw err

  console.log('status:', data)
}

// also:
//  - replicator.get(callback)
//  - replicator.del([rev, ] callback)
//  - replicator.put(doc, callback)

API

status

Get the status doc from CouchDB for this replication. The doc comes from /_active_tasks and has the type of 'replication' and 'target' of the db specified.

CouchReplicator.status(url, user, pass, db, callback)
// or on an existing CouchReplicator object:
replicator.status(callback)

get

Gets the replication doc from /_replicator/.

CouchReplicator.get(url, user, pass, db, callback)
// or on an existing CouchReplicator object:
replicator.get(callback)

del

Deletes the replication doc from /_replicator/?rev=revision, immediately stopping replication. Note that if rev is not supplied then a get() will be performed to look up the latest rev for this replication doc.

CouchReplicator.del(url, user, pass, db, [rev, ] callback)
// or on an existing CouchReplicator object:
replicator.del([rev, ] callback)

put

Put a new replication doc at /_replicator/ as specified by the doc parameter.

CouchReplicator.put(url, user, pass, db, doc, callback)
// or on an existing CouchReplicator object:
replicator.put(doc, callback)

Generally a replication doc should look something like this:

{
   "source": "https://fullfatdb.npmjs.com/registry",
   "target": "registry",
   "continuous": true,
   "user_ctx": {
       "name": "adminuser",
       "roles": [
           "_admin"
       ]
   }
}

See this gist for details about the _replicator database.

License

node-couch-replicator-api is Copyright (c) 2014 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Readme

Keywords

none

Package Sidebar

Install

npm i couch-replicator-api

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • rvagg