Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marianozunino/sequelize-typescript-paginate
https://github.com/marianozunino/sequelize-typescript-paginate
Last synced: about 7 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/marianozunino/sequelize-typescript-paginate
- Owner: marianozunino
- License: mit
- Created: 2020-12-30T14:20:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-06T14:29:48.000Z (about 4 years ago)
- Last Synced: 2024-12-14T20:19:44.495Z (about 1 month ago)
- Language: TypeScript
- Size: 235 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sequelize-typescript-paginate
[![npm version](https://img.shields.io/npm/v/sequelize-typescript-paginate.svg)](https://www.npmjs.com/package/sequelize-typescript-paginate)
[![Coverage Status](https://coveralls.io/repos/marianozunino/sequelize-typescript-paginate/badge.png)](https://coveralls.io/r/marianozunino/sequelize-typescript-paginate)
[![deps](https://david-dm.org/marianozunino/sequelize-typescript-paginate.svg)](https://david-dm.org/marianozunino/sequelize-typescript-paginate)
[![dev deps](https://david-dm.org/marianozunino/sequelize-typescript-paginate/dev-status.svg)](https://david-dm.org/marianozunino/sequelize-typescript-paginate/?type=dev)> Sequelize Base Model with pagination for Sequelize-Typescript
>
> Inspired on https://github.com/eclass/sequelize-paginate## Installation
```bash
npm i sequelize-typescript-paginate
```## Usege
```ts
import { PaginatedModel } from 'sequelize-typescript-pagination';
import { Sequelize, Column, DataType, ForeignKey, Table, HasMany } from 'sequelize-typescript';@Table({ tableName: 'book' })
export class Book extends PaginatedModel {
@Column({ type: DataType.STRING })
name: string;
@ForeignKey(() => Author)
@Column({ type: DataType.INTEGER })
authorId: string;
}@Table({ tableName: 'author' })
export class Author extends PaginatedModel {
@Column({ type: DataType.STRING })
name: string;
@HasMany(() => Book)
books: Book[];
}//...
//...
//...// Default page = 1 and pageSize = 25
const { docs, pages, total } = await Author.paginate();
// Or with extra options
const options = {
attributes: ['id', 'name'],
page: 1, // Default 1
pageSize: 25, // Default 25
order: [['name', 'DESC']],
where: { name: { [Op.like]: `%elliot%` } },
};
const { docs, pages, total } = await Author.paginate(options);
```**NOTE:** _If **options** includes **limit** or **offset** this will be ignored._
## License
[MIT](https://tldrlegal.com/license/mit-license)