Couch
:
:
:
: /modules/db/couch/lib/couch.js
: https://github.com/DecentCMS/DecentCMS/blob/master/modules/db/couch/lib/couch.js
Couch
Kind: global class
new Couch()
Couch encapsulates CouchDB data access for DecentCMS. It is not a generic CouchDB library, just a specialized data access library that implements content-centric DecentCMS operations on top of low-level HTTP calls.
| Param | Type | Description |
|---|---|---|
| [connection.server] | string |
The CouchDB server host name. Default is 'localhost'. |
| [connection.port] | number |
The port the CouchDB server answers on. Default is 5984. |
| [connection.protocol] | string |
'http' or 'https' depending on what protocolshould be used to access the database. The default is 'https'. |
| [connection.userVariable] | string |
The name of the environment variable that contains the user name to use to access the database. |
| [connection.passwordVariable] | string |
The name of the environment variable that contains the password to use to access the database. |
| config.database | string |
The name of the database. |
couch.get(query, callback)
Sends a simple get request to the database.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| query | string |
The part of the query URL that goes after '/database/'. |
| callback | function |
The callback function that will be called with an error and a parsed JavaScript object. |
couch.post(query, post, callback)
Sends a simple post request to the database.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| query | string |
The part of the query URL that goes after '/database/'. |
| post | object |
The object to serialize and use as the post's body. |
| callback | function |
The callback function that will be called with an error and a parsed JavaScript object. |
couch.send(options, callback)
Sends a simple request to the database.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| options | object |
The options object. |
| [options.verb] | string |
The verb to use. The default is "GET" if there is no post data, and "POST" otherwise. |
| options.query | string |
The part of the query URL that goes after '/database/'. |
| [options.post] | object |
The object to serialize and use as the post's body. |
| callback | function |
The callback function that will be called with an error and a parsed JavaScript object. |
couch.toItem(row) ⇒ object
Transforms a CouchDB row into a content item.
Kind: instance method of Couch
Returns: object - The item extracted from the row.
| Param | Type | Description |
|---|---|---|
| row | object |
The row. |
couch.fetchItems(keys, callback)
Fetches the items for which ids have been specified, and returns them as properties of an object, the property name being the id of the item.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| keys | Array |
The list of item ids to fetch. |
| callback | function |
The callback that receives an error and an object with properties that have the fetched item ids as their names, and the items as their values. |
couch.getIndexPage(options, callback)
Fetches a page of items in the database, filtered by id. This method creates an index in the database for each different filter used.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| options | object |
The options. |
| options.page | number |
The 0-based index of the page to fetch. |
| options.idFilter | RegExp |
The regular expression that the content item ids must satisfy to be in the index. |
| options.pageSize | number |
The number of items per page. The default is 10. |
| callback | function |
The function to call back with an error and an array containing the items for the page. |
couch.getFilteredIndexView(idFilter, callback)
Gets the name of a filtered view for the specified filter.
Kind: instance method of Couch
| Param | Type | Description |
|---|---|---|
| idFilter | RegExp |
A regular expression that ids should be filtered on. |
| callback | function |
A callback function that will get called with an error and the name of the view corresponding to the filter. |