get a list of databases

noCouchRelated - if you set this to true, you will only get databases, which are user generated (it simply filters all databases that name begins with '_')callback - callback function(error, response) for error and response handling

section - name of a section (a group of options)option - name of an optionvalue - new value for the option: if you set value to null, given option will be deletedcallback - function(error, section|option|saved) that will be called after getting the informations, or if new value was saved, or if there was an error

create admin account

Description: Creates an admin account. That means the config param will be set and the user document created.

cushion.createAdmin(name, password, callback);

name - name of the admin accountpassword - password of the admin accountcallback - function(error, created) that will be called after creating the admin account, or if there was an error

delete admin account

Description: Deletes the admin option at the configuration and the user document.

cushion.deleteAdmin(name, callback);

name - name of the admin accountcallback - function(error, deleted) that will be called after deleting the admin account, or if there was an error

list of active tasks

Description: Returns a list of active tasks.

cushion.activeTasks(callback);

callback - function(error, activeTasks) that will called, after getting the list of active tasks or if there was an error

list of generated uuids

Description: Returns a list of couchdb generated uuids.

cushion.uuids(callback);
cushion.uuids(count, callback);

count - number of uuids to generate [ default: 1 ]callback - function(error, uuidList) that will be called, after getting the list of uuids or if there was an error

server statistics

Description: Returns server statistics.

cushion.stats(callback);

callback - function(error, stats) that will be called, after getting the statistics of if there was an error

get log

Description: Returns the tail of the server's log file. There's also another param offset for the request to the couchdb, but it's not useful, look at the documentation http://wiki.apache.org/couchdb/HttpGetLog.

cushion.log(callback);
cushion.log(bytes, callback);

bytes - number of bytes which do you want from the tail [ default: 1000 ]callback - function(error, log) that will be called, after getting the log or if there was an error

restart server

Description: Restarts the server.

cushion.restart(callback);

callback - function(error, restart) function that will be called, after initializing the restart or if there was an error

make a low level request

Description: If there is something cushion doesn't offer to you, make a low level request to couchdb.

delete role

name - name of the userrole - role to delete from the userroles - list of roles to delete from the usercallback - function(error, deleted) that will be called after deleting the role(s), or if there was an error

get name of the database

Description: Get name of the database.

Example:

var dbName = db.name();

get all documents

Description: The additional options that you can set as first parameter, are the same that you can set at the view function, because the allDocuments function retrieves a special view at the couchdb _all_docs.

retrieving a view

designDocument - name of the design document after the "_design/"viewFunction - name of the view functionparams - additional query params, this are all the query parameters that are documented at the couchdb view apicallback - callback function(error, info, rows) for error and response handling

map - map function as a string and not as a functionreduce - reduce function as a string and not as a functionparams - additional query params, this are all the query parameters that are documented at the couchdb view apicallback - function(error, info, rows) that will be called, after getting the result or if there was an error

retrieving a list

design - name of the design document without the "_design/"list - name of the list functionotherDesign - name of another design document without the "_design/"view - name of the functionparams - additional params, the same that you can set at the view requestscallback - callback function(error, response) for error and response handling

retrieving show

design - name of the design document without the "_design/"show - name of the show functiondocumentId - id of the document, that will be set as param to the show functionparams - additional query params as key-value-pairs

compaction

callback - function(error, started) that will be called, after compaction was started or if there was an error

cleanup

db.cleanup(callback)

callback - function(error, started) that will be called, after cleanup was started or if there was an error

revision limit

Description Sets or gets the revision limit for documents (default is 1000).

db.revisionLimit(callback);
db.revisionLimit(limit, callback);

limit - number of the new limitcallback - function(error, limitOrSaved) that will be called after setting the limit (you will get a true as second parameter) or after getting the current limit or if there was an error

purging

Description: With this you can delete not only the document revision as itself, also the history will be removed. But be careful, purging can have bad side effects, so please look at the CouchDB Purge Documentation. The second argument purged on the callback give you feedback, which document revision could be purged.

db.purge(documents, callback);

documents - An object with keys that are the document id's and values that are arrays with revisions of the documents.callback - function(error, purged) that will be called, after calling the purge command on the couchdb or if there was an error

ensure full commit

callback - function(error, success) that will be called, after successfully started the save operation, or if there was an error

document api

getting document object

Description: If you set the ID and it will begin with _design/, then you will get a design document object instead of a normal document. Design documents have the same API as normal document plus some extra functions (look at design document api).

With given IDvar doc = db.document('foo' [, revision]);Without ID (if you want to create it later from the CouchDB) var doc = db.document();

load document

get / set content

Description: If you call body without arguments, you will retrieve the whole document content. If you only set one argument, and this argument is a string, you will set the complete body and overwrites all settings before. Otherwise you get the content of the given porperty. If you set 2 or more (you can set how much do you want) it will work as setter. If you set the body and the content argument (the last one) was explicitly set to 'undefined', the property will be deleted.

delete document

purging

Description: Look for more details at the purge command on database context. In document context this command works as a shortcut. But there's a difference: The second argument at the callback is only a boolean, that says if the document was purged (true) or not (false).

doc.purge(callback);
doc.purge(complete, callback);

complete - if you set this to true, it will purge the complete document (it makes a purge on the head revision)callback - function(error, purged) callback that will be called, if the purge command was done, or if there was an error

attachment api

save attachment

file - file path to the filecontentType - content type of the file (like image/png)name - name of the file it will have at the document. if you don't set it by yourself, cushion will use the filename insteadcallback - function that will be called, after saving the attachment

get attachment

doc.getAttachment(name, callback)

name - attachment name in the documentcallback - function that will be called, after the attachment was loaded

delete attachment

doc.deleteAttachment(name, callback)

name - attachment name in the documentcallback - function that will be called, after the attachment was deleted

design document api

get, create, update or delete views

Description: If you only set one argument, you will get the object with the string representation of the map and reduce functions. If you set map and reduce, you will set a view. If there is no views object in the body, it will be created, so you don't have to create it by yourself. If you set map explicitly to null, the view will be deleted.

name - name of the viewmap - string representation of the map functionreduce - string representation of the reduce function

get, create, update or delete lists

Description: If you only set one argument, you will get the string representation of the list function. If you set the content, it will save to the list. If there is no lists object in the body, it will be created, so you don't have to create it by yourself. If you set content explicitly to null, the list function will be deleted.

design.list(name)
design.list(name, content)

name - name of the listcontent - string representation of the list function

get, create, update or delete shows

Description: If you only set one argument, you will get the string representation of the show function. If you set the content, it will save to the show. If there is no shows object in the body, it will be created, so you don't have to create it by yourself. If you set content explicitly to null, the show function will be deleted.

design.show(name)
design.show(name, content)

name - name of the showcontent - string representation of the show function

getting or setting rewrites

Description With this you can set rewrite rules or get the current list of them. If you set no argument, you will get the current list of rewrites. If you set one argument, you will set the new rewrite list.

compaction

design.compact(callback)

callback - function(error, started) that will be called, after compaction was started or if there was an error

browser version

Cushion is also available in the browser. All you have to do is to load the cushion.browser.min.js. The initialization is a little bit different. In this example I use a proxy to connect to the CouchDB.

upcoming features

License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.