Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement count query type (RAW|ENTITY) #805

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

appotter
Copy link

This allows the query builder to choose a count query type which is counts for RAW or counts for ENTITY when an entity has inner join with many to many relations

ref issue #803 #758

import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { CatEntity } from './entities';
import {
  paginate,
  Pagination,
  IPaginationOptions,
  CountQueryTypeEnum,
} from 'nestjs-typeorm-paginate';

@Injectable()
export class CatService {
  constructor(
    @InjectRepository(CatEntity)
    private readonly repository: Repository<CatEntity>,
  ) {}

  async paginate(): Promise<Pagination<CatEntity>> {
    return paginate<CatEntity>(this.repository, {
      page: 1,
      limit: 30,
      // default is CountQueryTypeEnum.RAW
      countQueryType: CountQueryTypeEnum.ENTITY,
    });
  }
}

Screenshot 2022-11-27 at 00 10 17

@zarnautovic
Copy link

Will this be merged ? I have same problem with N-N relationships and this package.

@schuerg
Copy link

schuerg commented Mar 29, 2023

This solution works for me using TypeORM in a Nest.js project with query builder and joins calculating the correct totalCount.

Please review and merge someone with permissions.

@xadamxk
Copy link

xadamxk commented Jun 16, 2023

I could also benefit from this change.
@bashleigh could you help with this?

@leandro-gomez
Copy link
Contributor

@bashleigh is there a chance You can merge this please?

@Adebayo-Adesegun
Copy link

@bashleigh Looking forward to this PR being merged

@devi-prsd
Copy link

@bashleigh would also like to get this merged

@bashleigh
Copy link
Collaborator

Sorry it's been a while. I think I prefer this PR out of all the solutions I've seen. Don't suppose you'd mind adding some docs on the readme on how to use it and then I'd be happy to merge it and release as the next minor version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants