Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpalumickas/knex-cursor-pagination
Knex cursor pagination with Relay pagination support
https://github.com/jpalumickas/knex-cursor-pagination
apollo-server cursor-pagination knex relay relay-cursor-connections
Last synced: 30 days ago
JSON representation
Knex cursor pagination with Relay pagination support
- Host: GitHub
- URL: https://github.com/jpalumickas/knex-cursor-pagination
- Owner: jpalumickas
- License: mit
- Created: 2021-12-10T13:29:30.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-21T15:13:40.000Z (over 2 years ago)
- Last Synced: 2024-10-03T06:42:12.335Z (about 2 months ago)
- Topics: apollo-server, cursor-pagination, knex, relay, relay-cursor-connections
- Language: TypeScript
- Homepage:
- Size: 233 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Knex Cursor Pagination
Add stable cursor pagination to Knex query builder. This package also supports relay connection result.
## Installation
```sh
yarn add knex-cursor-pagination
```## Usage
```js
import { knexCursorPagination, getCursor } from 'knex-cursor-pagination'let query = knex
.queryBuilder()
.select('users.*')
.from('users')
.orderBy('posts.created_at', 'DESC')query = knexCursorPagination(query, { after: 'your-cursor' })
const results = await query
const endCursor = getCursor(results[results.length - 1])
```### Relay Pagination
Use with Relay pagination for example in Apollo Server
```js
import { relayConnection } from 'knex-cursor-pagination'const args = {
first: 10,
after: 'your-cursor',
}const query = knex
.queryBuilder()
.select('users.*')
.from('users')
.orderBy('posts.created_at', 'DESC')const result = relayConnection({
query,
args,
})
```## Known issues
* Currently not fully working with backwards pagination
* Using `orderByRaw` you need explicity to provide `ASC` or `DESC`## License
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).