-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support to query view #67
Comments
@raymondfeng, any thought on supporting query on view (or search indexes) for Cloudant connector? |
query view would be a cloudant specific function, it will be good if we can define it in cloudant connector, like:
then in juggler This would also be useful across all connectors. |
@jannyHou @raymondfeng , I think it's a good idea to have a consistent story in supporting views across connectors because they are not specific to Cloudant. Similar question in mssql: loopbackio/loopback-connector-mssql#26 |
|
Turns out the Other plans:
|
Steps taken to verify:
{
"_id": "_design/TestViewDDoc",
"_rev": "13-2738c014de2d5b6cfc02522d1bdc45fc",
"views": {
"hadtraining": {
"map": "function(doc) {\n if (doc.training) {\n emit(doc.number, doc.training);\n }\n}"
}
}
}
module.exports = function(app) {
var ds = app.dataSources.cldntlocal;
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('TestViewDDoc', 'hadtraining', function(err, results, rows) {
// `results` would be the data returned by quering that view
console.log('view total rows ', results.total_rows);
console.log('view results ', results.rows);
});
// Alternatively user can also specify the filter for view query
ds.connector.viewDocs('TestViewDDoc', 'hadtraining', {key: 5},
function(err, results) {
console.log('view by filter total rows ', results.total_rows);
console.log('view by filter results ', results.rows);
});
});
}; Results: | => node .
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer
view by filter total rows 4
view by filter results [ { id: '6d8d81bff8f54ccd35f499bc3e0799e8',
key: 5,
value: '10/02/2012' } ]
view total rows 4
view results [ { id: '6d8d81bff8f54ccd35f499bc3e03fe6c',
key: 1,
value: '12/20/2011' },
{ id: '6d8d81bff8f54ccd35f499bc3e0410f4',
key: 1,
value: '12/20/2011' },
{ id: '6d8d81bff8f54ccd35f499bc3e079366',
key: 3,
value: '12/05/2013' },
{ id: '6d8d81bff8f54ccd35f499bc3e0799e8',
key: 5,
value: '10/02/2012' } ]
^C Thanks @jannyHou for your help! |
Bug or feature request
Description of feature (or steps to reproduce if bug)
Couch connector supports to query the view, will cloudant connector support this feature?
https://www.npmjs.com/package/loopback-connector-couch
Link to sample repo to reproduce issue (if bug)
Expected result
Actual result (if bug)
Additional information (Node.js version, LoopBack version, etc)
The text was updated successfully, but these errors were encountered: