Skip to content

Commit

Permalink
Add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed May 30, 2017
1 parent 7ba32a8 commit 4248afa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ The `loopback-connector-cloudant` module is the Cloudant connector for the LoopB
- [Example Code](#example-code)
- [Discovery](#discovery)
- [Query](#query)
- [View](#view)
- [Testing](#testing)
- [Docker](#docker)
- [More Info](#more-info)
- [Feature backlog](#feature-backlog)
- [View](#view)
- [Index](#index)

<!-- /TOC -->
Expand Down Expand Up @@ -531,6 +531,34 @@ Not implemented yet, track it in story https://github.com/strongloop/loopback-co
- [LoopBack query](http://loopback.io/doc/en/lb3/Querying-data.html) support for: fields, limit, order, skip and where filters.
- Please check [Advanced Queries](https://github.com/strongloop/loopback-connector-cloudant/blob/master/doc/advanced-queries.md) for details about regex filter, nested filter and order.

# View

Given a design doc name and the view name in it, user can use a connector level function `viewDocs` to query the view.

Since `viewDocs` is a specific api for Cloudant connector only, it is not attached to the dataSource Object defined in loopback-datasource-juggler, which means the correct way to call it is `ds.connector.viewDocs`:

*/server/script.js*
```javascript
module.exports = function(server, cb) {
// Get Cloudant dataSource as `ds`
// 'cloudantDB' is the name of Cloudant datasource created in
// 'server/datasources.json' file
var ds = server.datasources.cloudantDB;


ds.on('connected', function() {
// 1. Please note `ds.connector.viewDocs()` is the correct way to call it,
// NOT `ds.viewDocs()`
// 2. This api matches the Cloudant endpoint:
// GET /db/_design/<design-doc>/_view/<view-name>
ds.connector.viewDocs('design_doc', 'view_name', cb);

// Alternatively user can also specify the filter for view query
ds.connector.viewDocs('design_doc', 'view_name', {key: 'filter'}, cb);
});
};
```

# Testing

- Cloudant local(docker image)
Expand Down Expand Up @@ -585,10 +613,6 @@ see the [docs section](https://github.com/strongloop/loopback-connector-cloudant
* Configurable "view based" or JSON indexes. [More Info>>](https://cloudant.com/blog/mango-json-vs-text-indexes)
* [Support uuid](https://github.com/strongloop/loopback-connector-cloudant/issues/104)

## View

Not implemented yet, track it in https://github.com/strongloop/loopback-connector-cloudant/issues/67

## Index

To be updated
4 changes: 2 additions & 2 deletions test/cloudant.view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ function generateSamples() {
var samples = [
{
model: 'purchase',
'customer_id': 1,
customerId: 1,
basket: ['food', 'drink'],
},
{
model: 'purchase',
'customer_id': 2,
customerId: 2,
basket: ['book', 'video'],
},
{
Expand Down

0 comments on commit 4248afa

Please sign in to comment.