Comments (7)
@raymondfeng, any thought on supporting query on view (or search indexes) for Cloudant connector?
from loopback-connector-cloudant.
query view would be a cloudant specific function, it will be good if we can define it in cloudant connector, like:
// in `lib/cloudant.js`
Cloudant.prototype.queryView() {
// code
}
then in juggler lib/datasource.js
, we can mix certain connector specific functions to Model, like how we mix DAO functions to model in https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/datasource.js#L585
This would also be useful across all connectors.
@raymondfeng Any thought?
from loopback-connector-cloudant.
@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
from loopback-connector-cloudant.
-
option1: db.view(designname, viewname, [params], [callback])
- This is the main function exported by nano to query view.
- If our goal is to support it, we can define a method
Cloudant.prototype.view(viewname, [params], cb)
,designname
can be read from loopback model name,viewname
andparams
are inputs. - endpoint: GET/Model/view
-
option2: couchdb view(map and reduce)
- If we want to support user define
map
andreduce
functions, they should be provided when creating the model. - GET/Model/view/ get all docs queried by a view
- PUT/Model/view/ update a view(an entry in views) in a design doc
- If we want to support user define
-
option3: Another thought is, make it a datasource level api, instead of a model level, like
automigrate
, and user can provide any designname, doesn't have to map a loopback model name.
Now we fix ddoc name to be'lb-index-ddoc-' + modelName
, user cannot change it, which means if they already have some data in cloudant database, using their own ddoc name, and includes views in the design doc, they could not map it to our model.
I have considered supporting discover views then make view a loopback model, but seems couchdb doesn't have an api to return all views, it's only able to return all indexes.
from loopback-connector-cloudant.
Turns out the view
could not be a model level api with current design, explained in #15 (comment)
Other plans:
- strategy1: Support those design functions like view as datasource level functions, so a view don't need to be created in a lb-model's design doc.
- srategy2: Use two design docs(one for index one for view) to represent a loopback model.
from loopback-connector-cloudant.
Steps taken to verify:
- Create a DDoc on cloudant db called
TestViewDDoc
with a viewhadtraining
{
"_id": "_design/TestViewDDoc",
"_rev": "13-2738c014de2d5b6cfc02522d1bdc45fc",
"views": {
"hadtraining": {
"map": "function(doc) {\n if (doc.training) {\n emit(doc.number, doc.training);\n }\n}"
}
}
}
- Create some docs which satisfy the view criteria
- Add boot script to a test LB app which is connected to the same cloudant db and queries for the view:
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!
from loopback-connector-cloudant.
connect to https://github.com/strongloop-internal/scrum-apex/issues/240
from loopback-connector-cloudant.
Related Issues (20)
- Out dated / error in dependancies HOT 2
- Count returns a max of 25 HOT 5
- Query "like and case insensitive" with issues HOT 7
- Add support Geospatial queries HOT 5
- Fix the filter for hasManyThrough relation HOT 2
- Fix CI - 2 test cases failed HOT 3
- Run shared tests from both v3 and v4 of juggler
- FindById doesn't use Cloudant Read by Id method HOT 8
- [Spike] Add Support for Partitioned Databases HOT 18
- Update driver to nodejs/cloudant HOT 5
- Support creating partitioned index HOT 1
- Optimize query by reading partition key from payload HOT 1
- Compose the _id for a document in a partition database HOT 3
- [Epic] Add Support for Partitioned Database HOT 2
- findAll: Read partitionKey from `options` HOT 3
- Optimize findById for partitioned database HOT 4
- [Epic] Add Support for Partitioned Database (Post MVP) HOT 5
- [Blog] Blog post about the support for partitioned database HOT 2
- Invalid key partitioned using with Cloudant docker locally HOT 6
- Move to @ibm-cloud/cloudant HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-connector-cloudant.