rxjs-couch
RxJS-flavored APIs for CouchDB
Installation
IMPORTANT: This library only supports RxJS 5.x.
Looking for RxJS 4.x support? Try rx-couch. (Same name but replace 'rxjs' with 'rx'.)
NPM
npm install --save rxjs-couch
Usage
const RxCouch = ; const server = 'http://my.host:5984'; // List all databases on the server.// http://docs.couchdb.org/en/latest/api/server/common.html#all-dbsserver ; // -> ['_replicator', '_users', 'my-database', etc...] // Create a database. By default, this will ignore 412 errors on the assumption// that this means "database already exists."// http://docs.couchdb.org/en/latest/api/database/common.html#put--dbserver ; // fires when done // Create a database and fail if the database already exists.// http://docs.couchdb.org/en/latest/api/database/common.html#put--dbserver ; // In this example, an error event would be sent. // Delete a database.// http://docs.couchdb.org/en/latest/api/database/common.html#delete--dbserver ; // fires when done // Replicate a database.// http://docs.couchdb.org/en/latest/api/server/common.html#replicateserver ; // -> {history: [...], ok: true, etc...} // Create a database object to interact with a single database on the server.// WARNING: Does not create the database. See .createDatabase above.const db = server; // Create a new document and let CouchDB assign an ID.// http://docs.couchdb.org/en/latest/api/database/common.html#post--dbdb ; // -> {id: '(random)', ok: true, rev: '1-(random)'} // Create a new document using an ID that I choose.// http://docs.couchdb.org/en/latest/api/document/common.html#put--db-dociddb ; // -> {id: 'testing123', ok: true, rev: '1-(random)'} // Update an existing document, replacing existing value// http://docs.couchdb.org/en/latest/api/document/common.html#put--db-dociddb ; // -> {id: 'testing123', ok: true, rev: '2-(random)'} // Update an existing document, merging new content into existing value.db ; // -> {id: 'testing123', ok: true, 'rev': '3-(random)'} // Update an existing document, replacing existing value, but avoiding// write if new value exactly matches existing.db ; // -> {id: 'testing123', ok: true, rev: '3-(random)', noop: true} // Get the current value of an existing document.// http://docs.couchdb.org/en/latest/api/document/common.html#get--db-dociddb ; // -> {_id: 'testing123', _rev: '3-(random)', foo: 'baz', flip: true} // Get the value of an existing document with query options.// All options described under query parameters below are supported:// http://docs.couchdb.org/en/latest/api/document/common.html#get--db-dociddb ; // -> {_id: 'testing123', _rev: '1-(random)', foo: 'baz'} // Observe the value of an existing document over time.// Returns the current document value soon after the call is issued// and monitors the value until the subscription is terminated.// Use this sparingly; having many of these open at once could lead to// unacceptable server load. db ; // -> one or more results of the form // {_id: 'testing123', _rev: '1-(random)', foo: 'baz'} // Get information about several documents at once.// All options described under query parameters below are supported:// http://docs.couchdb.org/en/latest/api/database/bulk-api.html#get--db-_all_docsdb ; // -> {offset: 0, rows: {...}, total_rows: 5} // Delete an existing document. Both arguments (doc ID and rev ID) are required.// http://docs.couchdb.org/en/latest/api/document/common.html#put--db-dociddb ; // -> {id: 'testing123', ok: true, rev: '4-(random)'} // Replicate from another database into this database.// http://docs.couchdb.org/en/latest/api/server/common.html#replicatedb ; // -> {history: [...], ok: true, etc...} // Monitor changes to the database.// http://docs.couchdb.org/en/latest/api/database/changes.htmldb ; // -> any number of result objects of the form (one per document): // { // "changes": [ // { // "rev": "2-7051cbe5c8faecd085a3fa619e6e6337" // } // ], // "id": "6478c2ae800dfc387396d14e1fc39626", // "seq": 6 // } // // The exact form of the responses will vary depending on the // options specified. // // If feed: "longpoll" appears in the options object, the changes // feed is monitored continuously until the subscription is dropped. // It is an error to use feed: "continuous".
If any HTTP errors occur, they will be reported via onError
notification on
the Observable using the HTTP error object from rxjs-fetch.
License
MIT