# dynongo-pager

> Easy paging for DynamoDB with dynongo

Latest version **0.3.0** (published 2020-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install dynongo-pager
pnpm add dynongo-pager
yarn add dynongo-pager
bun add dynongo-pager
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2020-09-28 |
| First published | 2017-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 0 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Sam Verschueren |
| Maintainers | samverschueren |
| Keywords | dynamodb, aws, dynongo, database, db, paging, pages |

## Links

- npm: https://www.npmjs.com/package/dynongo-pager
- Repository: https://github.com/SamVerschueren/dynongo-pager
- Homepage: https://github.com/SamVerschueren/dynongo-pager#readme
- Issues: https://github.com/SamVerschueren/dynongo-pager/issues
- npm.io page: https://npm.io/package/dynongo-pager

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2020-09-28
- 0.2.0 — 2018-01-22
- 0.1.0 — 2017-07-28

## README

# dynongo-pager [![Build Status](https://travis-ci.org/SamVerschueren/dynongo-pager.svg?branch=master)](https://travis-ci.org/SamVerschueren/dynongo-pager)

> Easy paging for DynamoDB with [dynongo](https://github.com/SamVerschueren)


## Install

```
$ npm install --save dynongo-pager
```

> Note: this package has a peer dependency on `dynongo@0.14.0` or higher.


## Usage

```js
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*<br>
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`<br>
Options: `1` `-1`

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


## Related

- [dynongo](https://github.com/SamVerschueren/dynongo) - MongoDB like syntax for DynamoDB


## License

MIT © [Sam Verschueren](https://github.com/SamVerschueren)

---
_Source: https://npm.io/package/dynongo-pager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
