Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/charlie-hadden/kysely-paginate
Pagination helpers for use with kysely
https://github.com/charlie-hadden/kysely-paginate
Last synced: 2 months ago
JSON representation
Pagination helpers for use with kysely
- Host: GitHub
- URL: https://github.com/charlie-hadden/kysely-paginate
- Owner: charlie-hadden
- License: mit
- Created: 2023-04-13T22:16:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-23T17:53:36.000Z (about 1 year ago)
- Last Synced: 2024-04-29T22:28:37.708Z (9 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/kysely-paginate
- Size: 142 KB
- Stars: 51
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kysely - kysely-paginate - Pagination helpers for use with [Kysely](https://kysely.dev). ![npm](https://img.shields.io/npm/dw/kysely-paginate?style=flat-square) ![GitHub stars](https://img.shields.io/github/stars/charlie-hadden/kysely-paginate?style=flat-square) ![NPM](https://img.shields.io/npm/l/kysely-paginate?style=flat-square) (Addons)
README
# kysely-paginate
Pagination helpers for use with [Kysely](https://github.com/kysely-org/kysely).> :warning: **This is a work in progress!** This library is still very early in development. Things won't work, things will be missing, and there will be breaking changes.
## Cursor pagination
```ts
const query = db
.selectFrom("blogPosts")
.select(["id", "title", "body", "authorId"])
.where("authorId", "=", 1);const result = await executeWithCursorPagination(query, {
perPage: 10,
fields: [
{ expression: "title", direction: "desc" },
{ expression: "id", direction: "asc" },
],
parseCursor: (cursor) => ({
title: cursor.title,
id: parseInt(cursor.id, 10),
}),
});
```## Offset pagination
```ts
const query = db
.selectFrom("blogPosts")
.select(["id", "title", "body", "authorId"])
.where("authorId", "=", 1)
.orderBy("title", "desc")
.orderBy("id", "asc");const result = await executeWithOffsetPagination(query, {
perPage: 10,
page: 1,
})
```