Skip to content
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

allow usage of limit parameter in pouchdb adapter queries #193

Merged
merged 2 commits into from Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -289,6 +289,28 @@ export default Ember.Route.extend({
});
```

Limit to 5 documents.

```javascript
// app/routes/smasher/index.js
import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.query('smasher', {
filter: {
name: 'Mario',
debut: { '$gte': null }
},
sort: [
{ debut: 'desc' }
],
limit: 5
})
}
});
```

Note that this query would require a custom index including both fields `data.name` and `data.debut`. Any field in `sort` must also be included in `filter`. Only `$eq`, `$gt`, `$gte`, `$lt`, and `$lte` can be used when matching a custom index.

### store.queryRecord(model, options)
Expand Down
4 changes: 4 additions & 0 deletions addon/adapters/pouch.js
Expand Up @@ -351,6 +351,10 @@ export default DS.RESTAdapter.extend({
queryParams.sort = this._buildSort(query.sort);
}

if (!Ember.isEmpty(query.limit)) {
queryParams.limit = query.limit;
}

return db.find(queryParams).then(pouchRes => db.rel.parseRelDocs(recordTypeName, pouchRes.docs));
},

Expand Down