From 21819da7e5de7a28da5075357f5f43a5ac11401d Mon Sep 17 00:00:00 2001 From: Dmitri Akatov Date: Fri, 15 Sep 2017 15:38:27 +0100 Subject: [PATCH] allow usage of skip parameter in pouchdb adapter queries --- README.md | 22 ++++++++++++++++++++++ addon/adapters/pouch.js | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/README.md b/README.md index aee8a1f..ad8bdc8 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,28 @@ export default Ember.Route.extend({ }); ``` +Skip the first 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' } + ], + skip: 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) diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index cc67f21..7eb56c2 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -363,6 +363,10 @@ export default DS.RESTAdapter.extend({ queryParams.limit = query.limit; } + if (!Ember.isEmpty(query.skip)) { + queryParams.skip = query.skip; + } + return db.find(queryParams).then(pouchRes => db.rel.parseRelDocs(recordTypeName, pouchRes.docs)); },