Giter Club home page Giter Club logo

couch-stream's Introduction

CouchStream

A Stream interface for couchdb.

example

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 = CouchStream.save({database: 'tests'})

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

or even better: USE PIPE

documentSource.pipe(save)

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 

CouchStream.changes(opts).pipe(writable)

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(CouchStream.save({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 = 
      CouchStream.wait({
        database: 'tests'
      , poll: 100    //poll for the database every 100 ms. (default: 500)
      })

var es = require('event-stream')

es.connect(
  readableStreamOfDocuments,
  waitForExists,
  CouchStream.save({database: 'tests'})
)

create

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')

es.connect(
  readableStreamOfDocuments,
  createDB,
  CouchStream.save({database: 'tests'})
)

#TODO

##view

(pull sections at a time respecting pause, etc)

##delete

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

couch-stream's People

Contributors

dominictarr avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.