Socket
Socket
Sign inDemoInstall

nestjs-pagination-typeorm

Package Overview
Dependencies
6
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nestjs-pagination-typeorm

Paginate and sort helpers for TypeORM and NestJS.


Version published
Maintainers
1
Created

Readme

Source

nestjs-pagination-typeorm

Paginate and sort helpers for TypeORM and NestJS.

  • Filter operators (eq, like, ne, gt, gte, in, lt, lte, btw)
  • Sort by multiple columns
  • Paginate with cursor or offset
  • Order results by multiple columns
  • Extends typeorm added Unit of work pattern (transactional queries)

Documentation in progress

Installation

$ npm install --save nestjs-pagination-typeorm

Usage

Create Repository

import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { BaseRepository } from "nestjs-pagination-typeorm";

export class UserRepository extends BaseRepository<User> {
  public constructor(@InjectRepository(User) repository: Repository<User>) {
    super(User);
  }
}

Create Service

import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { UserRepository } from "./user.repository";

@Injectable()
export class UserService {
  public constructor(
    @InjectRepository(UserRepository)
    private readonly userRepository: UserRepository,
  ) {}

  public async findAll(filter: PaginationFilter<User>): Promise<PaginationResult<User>> {
    return this.userRepository.paginate(filter);
  }
}

Create Controller

import { Controller, Get, Query } from "@nestjs/common";
import { Paginate, PaginationDto } from "nestjs-pagination-typeorm";
import { UserService } from "./user.service";

@Controller("users")
export class UserController {
  public constructor(private readonly userService: UserService) {}

  @Get()
  public async findAll(@Paginate() filter: PaginationFilter<User>): Promise<PaginationDto<User>> {
    return this.userService.findAll(filter);
  }
}

Keywords

FAQs

Last updated on 01 Nov 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc