deptyped / prisma-extension-pagination

Prisma Client extension for pagination
https://npmjs.com/prisma-extension-pagination
MIT License
243 stars 18 forks source link

Add typing for Prisma client with pagination extension #19

Open btd1337 opened 11 months ago

btd1337 commented 11 months ago

Hi,

When using pagination with NestJs it's necessary to code like this:

// prisma.service.ts

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
    public readonly pagination;

    constructor() {
        super();
        this.pagination = this.$extends(pagination);
      }

      async onModuleInit(): Promise<void> {
        await this.$connect();
      }
}
// in any repository class

findAll(id: string) {
    return this.prismaService.pagination. // no type identification from here on

    // expected: return this.prismaService.pagination.any_model.paginate().withPages();
}

But since pagination variable is not typed, when you try to use paginator, autocomplete is not generated anywhere, and also, any schema breakchanges are not detected by prisma.

Is It possible to add pagination types to this library?

Problem reference: https://github.com/deptyped/prisma-extension-pagination/issues/7#issuecomment-1778988261

AlexRMU commented 7 months ago

Look at this