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

dynongo-pager

v0.3.0

Published

Easy paging for DynamoDB with dynongo

Downloads

2,775

Readme

dynongo-pager Build Status

Easy paging for DynamoDB with dynongo

Install

$ npm install --save dynongo-pager

Note: this package has a peer dependency on [email protected] or higher.

Usage

const db = require('dynongo');
const pager = require('dynongo-pager');

// Connect with the database
db.connect();

const Document = db.table('Document');

pager(Document, {user: '1'}, {
	limit: 2,
	elementIndex: () => ['user', 'date']
}).then(page1 => {
	console.log(page1);
	/**
	 * {
	 *   items: [
	 *     { user: '1', date: '2017-07-28T18:33:12Z', src: 'foo.pdf' },
	 *     { user: '1', date: '2017-07-29T12:18:56Z', src: 'bar.pdf' }
	 *   ],
	 *   paging: {
	 *     after: 'eyJ1c2VyIjoiMSIsImRhdGUiOiIyMDE3LTA3LTI5VDEyOjE4OjU2WiJ9'
	 *   }
	 * }
	 */

	return pager(Document, {user: 1}, {
		limit: 2,
		after: page1.paging.after,
		elementIndex: () => ['user', 'date']
	});
}).then(page2 => {
	console.log(page2);
	/**
	 * {
	 *   items: [
	 *     { user: '1', date: '2017-07-30T06:26:11Z', src: 'unicorn.pdf' },
	 *     { user: '1', date: '2017-07-31T08:04:10Z', src: 'rainbow.pdf' }
	 *   ],
	 *   paging: {
	 *     before: 'eyJ1c2VyIjoiMSIsImRhdGUiOiIyMDE3LTA3LTMwVDA2OjI2OjExWiJ9',
	 *     after: 'eyJ1c2VyIjoiMSIsImRhdGUiOiIyMDE3LTA3LTMxVDA4OjA0OjEwWiJ9'
	 *   }
	 * }
	 */
});

In the example above, we query the Documents table to retrieve all the documents of the user with ID 1. The user property is the partion key, and the date property is the sort key.

The before value is the base64 encoded representation of the index (partition key and sort key) of the first element in the items list. The after value is the base64 encode representation of the index of the last element in the items list.

API

pager(table, index, [options])

table

Type: Table

Dynongo table.

index

Type: Object

Partition key.

options

elementIndex

Required Type: function

Function that should return the properties being part of the index. The function accepts an argument being the name of the index that's being used to query the database.

limit

Type: number

Limit of items per page. If not provided, the page will retrieve as many items as possible which is 1MB in size.

after

Type: string

Token to retrieve the next page.

before

Type: string

Token to retrieve the previous page.

from

Type: string number boolean

Lower boundary of the sort key.

to

Type: string number boolean

Upper boundary of the sort key.

indexName

Type: string

Name of the index to use.

select

Type: string

Space separated list of the values you want to retrieve.

where

Type: object

Filter object.

sort

Type: number Options: 1 -1

Sort the values ascending (1) or descending (-1).

Related

  • dynongo - MongoDB like syntax for DynamoDB

License

MIT © Sam Verschueren