From 30f3acab4a50318718cb634c668e572f880d9b32 Mon Sep 17 00:00:00 2001 From: Dmitri Akatov Date: Fri, 8 Sep 2017 18:54:59 +0100 Subject: [PATCH 1/2] allow usage of limit parameter in pouchdb adapter queries --- addon/adapters/pouch.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index c2f137e..5d90fd1 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -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)); }, From bf5ed146034209f18dc134a918d908d5c030e39f Mon Sep 17 00:00:00 2001 From: Dmitri Akatov Date: Fri, 15 Sep 2017 15:34:08 +0100 Subject: [PATCH 2/2] add example for usage of the limit parameter --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 9fa17c6..aee8a1f 100644 --- a/README.md +++ b/README.md @@ -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)