🏳🌈 Pagination helper method for Sequelize models.
🌐 Description
Under the hood, nestjs-sequelize-paginate makes use of the nest framework, and you also need to install nestjs, and sequelize !
📦 Integration
To start using it, we first install the required dependencies. In this chapter we will demonstrate the use of the paginate for nestjs.
You simply need to install the package !
// We install with npm, but you could use the package manager you prefer !npm install -save nestjs-sequelize-paginate
▶️ Getting started
Once the installation process is complete, we can import the PaginateModule into the root AppModule
;;
The forRoot() method supports all the configuration properties exposed by the paginate constuctor . In addition, there are several extra configuration properties described below.
Name | Description | Type | Default |
---|---|---|---|
url | If you want a global url | string | null |
isGlobal | If you want the module globally | boolean | true |
showUrl | If you want the url to be shown in the results | boolean | false |
structure | Una forma de estructura de respuesta | 'simple' | 'segmented' | simple |
details | Una forma de respuesta | 'necessary' | 'complete' | complete |
defaultPage | Numeros de pagina por defecto globalmente | number | 1 |
defaultOffset | Numeros de cantidad por pagina globalmente | number | 5 |
showOffset | Si quere offset se muestre en las url globalmente | boolean | false |
Service
Sequelize implements the Active Record pattern. With this pattern, you use model classes directly to interact with the database. To continue the example, we need at least one model. Let's define the User Model.
;;;
Next, let's look at the UserModule:
;;;;
Decorator
As you saw, we're using a decorator, '@PaginateQuery'.
The decorator receives only one option as a parameter, which is all
, this allows to add the offset through the url !
This decorator returns the following to you !
⭐ Support for
Sass-colors is an open source project licensed by MIT. You can grow thanks to the sponsors and the support of the amazing sponsors. If you want to join them, contact me here.
🎩 Stay in touch
- Author Yoni Calsin
- Twitter Yoni Calsin
📜 License
Sass-colors is MIT licensed.