npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pouchdb-paginators

v2.0.0

Published

Paginator plugin for PouchDB queries.

Downloads

3

Readme

PouchDB-Paginators

CI Coverage Status Stability NPM Version JS Standard Style

A plugin that adds to PouchDB methods like .paginateAllDocs() which return paginators over results. Paginators can be iterated over without loading all results into memory, and they effectively coordinate per-page query settings with usual options like reduce: false or include_docs: true.

Pagination in PouchDB and CouchDB is rather unintuitive, especially for map/reduce views. This plugin intends to make it easy and reliable. For example:

const PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-paginators'))

const db = new PouchDB('...')

const pager = db.paginateQuery('queries/example')
// now you can page through results
for await (const results of pager.pages()) {
  // do what thou wilt
}
// and you can even page backwards
for await (const results of pager.reverses()) {
  // do what thou wilt, but with feeling this time!
}

Compatibility Note

Pagination using db.find() only works with a PouchDB instance representing a connection to a CouchDB installation. Otherwise, because PouchDB does not currently support bookmarks, your paginators will always return the same page. If you are using PouchDB with any non-CouchDB storage backend, like leveldb or indexeddb, .paginateFind() will not be able to page forward.

Usage

New Methods

The plugin adds three methods which mirror existing query methods, accepting all the same options, but which return paginators:

  • db.paginateAllDocs() mirrors db.allDocs().
  • db.paginateQuery() mirrors db.query().
  • db.paginateFind() mirrors db.find().

Paginator

All paginators have the same API. The pages that paginators return have a default limit of 20 results.

paginator.hasPrevPage

A getter that returns a boolean indicating whether the paginator has a previous page.

paginator.hasNextPage

A getter that returns a boolean indicating whether the paginator has a next page. This is optimistically set to true when the paginator is first created.

async paginator.getNextPage()

Returns the next page of results, as though you had called the query or find method itself.

async paginator.getPrevPage()

Returns the previous page of results, as though you had called the query or find method itself.

async paginator.getSamePage()

Returns the same page of results as the last method that returned a page, as though you had called the query or find method itself.

async * paginator.pages()

Returns an iterator that allows you to use a for-loop to loop through pages of results.

for await (const results of pager.pages()) {
  // do what thou wilt
}

async * paginator.reverse()

Returns an iterator that allows you to use a for-loop to loop through pages of results in reverse.

for await (const results of pager.reverse()) {
  // do what thou wilt, in reverse!
}

Development

If you encounter a bug or would like to request a feature, please file an issue!

If you are submitting a patch, please be a good neighbor and include tests!

To hack on this project locally, first get its source and install its dependencies:

$ git clone [email protected]:garbados/pouchdb-paginators.git
$ cd pouchdb-paginators
$ npm i

Then you can run the test suite:

$ npm test

License

Apache License 2.0