npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

typeorm-easy-paginate

v1.1.0

Published

Easy and simple pagination plugin to build pagination objects with TypeORM

Downloads

17

Readme

GitHub license GitHub stars GitHub issues GitHub package.json version

typeorm-easy-paginate

The fast and easy way to create paging objects in Express with TypeORM

Installation

Pre-requisites:

  • typeorm

NPM:

npm install typeorm-easy-paginate
Yarn
yarn add typeorm-easy-paginate

Usage

Import the plugin where you want to use it

import { paginate } from "typeorm-easy-paginate";

Now we can start paging our queries.

We create our controller and call the function paginate

import { Response, Request } from 'express';
import { Example } from "../entity/example";
import { paginate } from "typeorm-easy-paginate";

// Example controller
export class exampleController {
    public async example(req: Request, res: Response) {
        
        /* Replace de 'Example' with your entity */
        const paginateList = await paginate<Example>(Example, { /*Paginate options here*/ }, {/*TypeOrm repository querys here*/});

        return res.json(paginateList)
    }
}

In the paging options you can pass the page, and the number of records per page either manually or from query params.

NOTE:

By default it will always start from page 1.

If you do not pass the number of records per page, the total number of records in the table will be taken by default

const paginateList = await paginate<Example>(Example, {page: 1, perPage: 10}, {});

You can pass options from query params. You must convert it to numeric like this

let page = parseInt(<string>req.params.page);
let perPage = parseInt(<string>req.params.perPage);

And now you can pass to the options

const paginateList = await paginate<Example>(Example, {page, perPage}, {});

Query

In addition to the paging options, you can make queries like these.

PD: You can use all FindOptions of TypeORM

const paginateList = await paginate<Example>(Example, {page, perPage}, {where: { firstName: "Timber" }});

Request:

You can make the url like this

http://localhost:3000/api/jobs?page=1&perPage=15

Or

http://localhost:3000/api/jobs

Example result:

{
  "content": [
    {
      "id": 13,
      "job": "001"
    },
    {
      "id": 14,
      "job": "002"
    }
  ],
  "pagination": {
    "page": 1,
    "perPage": 2,
    "totalPage": 30,
    "totalItems": 60
  }
}

Contributions:

If you like to make a contribution you can send a PR, I will be very grateful for your help. PULL REQUESTS