Skip to content

Commit

Permalink
Merge pull request #193 from akatov/allow-query-limit
Browse files Browse the repository at this point in the history
allow usage of limit parameter in pouchdb adapter queries
  • Loading branch information
broerse committed Sep 16, 2017
2 parents f132f6a + bf5ed14 commit 3607fee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,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

0 comments on commit 3607fee

Please sign in to comment.