Stream interface to couch
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A Stream interface for couchdb.


basically just point CouchStream at your couch server ande start spraying documents in!

create a CouchStream and start writing documents to it.
has the same interface as Stream

var CouchStream = require('couch-stream')
var save ={database: 'tests'})

save.write({doc: "YES"})

or even better: USE PIPE


all the following examples use EventStream
a toolkit for working creating and using Streams.

common options

each CouchStream function takes options and returns a stream.
the following options apply to all functions:

{ database: database      // database  (mandatory)
, port: port              // port (default: 5984)
, host: host              // host (default: 'localhost')
, url: 
  'http://HOST:PORT/DB'   //optional, in place of using database, host, & port

changes (opts)

read changes from the database, as they occur.

wraps Follow
so options that work for follow, will work the same here.

var opts = {
  since: seq              // sequence number to listen from (default: 'now')
, include_docs: boolean   // emit docs at each change (default: false)
, filter:   filter        // a path to a design doc or a filter function (default: null (do not filter))
} //plus options 


save (opts)

Save a stream of documents to the database,
wraps request
so options that work for request will also work here.

requires only the common options.

readable.pipe({database: 'tests'})) 

get (opts)

retrive the docs from a Stream of ids.
must be stream of strings, or objects with _id or id properties.

requires only the common options.

ids.pipe(CouchStream.get({database: 'tests'})) 

wait (opts)

buffer the stream until the database exists, (makes sense ahead of save)

no documents will be let through until the database has exists.
does not create the database.

var waitForExists = 
        database: 'tests'
      , poll: 100    //poll for the database every 100 ms. (default: 500)

var es = require('event-stream')

  waitForExists,{database: 'tests'})


create a database, buffering the stream until the database is ready.
(makes sense ahead of save)

var createDB = 
  CouchStream.create({database: 'tests'})

var es = require('event-stream')

  createDB,{database: 'tests'})



(pull sections at a time respecting pause, etc)


delete documents from a stream of ids (similar to get).