Created
January 20, 2019 23:21
-
-
Save danielAlbuquerque/39dfdefdfbdfcbed80912a5d64ea4eff to your computer and use it in GitHub Desktop.
Pouch pagination example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pouchDB = require('pouchdb-node') | |
const db = new pouchDB('database_name') | |
let options = { limit: 5 } | |
async function fetchNextPage () { | |
try { | |
const result = await db.allDocs(options) | |
console.log(result.rows) | |
if (result.rows.length > 0) { | |
options.startKey = result.rows[result.rows.length - 1].id | |
options.skip = options.skip == undefined ? options.limit : options.skip + options.limit | |
} | |
} catch(e) { | |
console.error(e) | |
} | |
} | |
async function main() { | |
await fetchNextPage() | |
await fetchNextPage() | |
await fetchNextPage() | |
await fetchNextPage() | |
await fetchNextPage() | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment