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 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-extension-find-and-count

v1.0.2

Published

This extension for Prisma provides `findAndCount` method doing `findMany` and `count` in one transaction to avoid difference in data.\ All you need is to extend prisma in singleton ```javascript import { findAndCountExtension } from 'prisma-extension-find

Readme

This extension for Prisma provides findAndCount method doing findMany and count in one transaction to avoid difference in data.
All you need is to extend prisma in singleton

import { findAndCountExtension } from 'prisma-extension-find-and-count'
...
MyPrismaClientSingleton.$extends(findAndCountExtension)

and then use it

// options are options for findMany like 'where', 'data', 'select', etc.
this.prisma.someModel.findAndCount(options)

If you're looking for how to setup Prisma as singleton to avoid different contexts and instances of PrismaClient, here what I've got for NestJS (thanks to @micobarac answer in https://github.com/prisma/prisma/issues/18628#issuecomment-2655850811)

folder structure

src
--prisma
----prisma.extensions.ts
----prisma.module.ts
----prisma.provides.ts
----prisma.service.ts
app.module.ts

now content
prisma.extensions.ts - here we can define our extension if we don't want to pull them from npm

import { Prisma } from '@prisma/client'

export const existsExtension = Prisma.defineExtension({
  name: 'exists-extension',
  model: {
    $allModels: {
      async exists<T>(
        this: T,
        where: Prisma.Args<T, 'findFirst'>['where'],
      ): Promise<boolean> {
        const context = Prisma.getExtensionContext(this)
        const count = await (context as any).count({
          where,
          take: 1,
        } as Prisma.Args<T, 'count'>)
        return count > 0
      },
    },
  },
})

export const softDeleteExtension = Prisma.defineExtension({
  name: 'soft-delete-extension',
  model: {
    $allModels: {
      async softDelete<T>(
        this: T,
        where: Prisma.Args<T, 'update'>['where'],
      ): Promise<Prisma.Result<T, unknown, 'update'>> {
        const context = Prisma.getExtensionContext(this)
        return await (context as any).update({
          where,
          data: {
            deletedAt: new Date(),
          },
        } as Prisma.Args<T, 'update'>)
      },
    },
  },
})

export const findAndCountExtension = Prisma.defineExtension((client) => {
  return client.$extends({
    name: 'find-and-count-extension',
    model: {
      $allModels: {
        async findAndCount<Model, Args>(
          this: Model,
          args: Prisma.Exact<Args, Prisma.Args<Model, 'findMany'>>,
        ): Promise<[Prisma.Result<Model, Args, 'findMany'>, number]> {
          return await client.$transaction([
            (this as any).findMany(args),
            (this as any).count({ where: (args as any).where }),
          ])
        },
      },
    },
  })
})

prisma.provides.ts - here we turn on our extensions through withExtensions method

import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'
import { PrismaClient } from '@prisma/client'
import {
  existsExtension,
  findAndCountExtension,
  softDeleteExtension,
} from './prisma.extensions'

@Injectable()
export class PrismaProvider
  extends PrismaClient
  implements OnModuleInit, OnModuleDestroy
{
  private static initialized = false

  async onModuleInit() {
    if (!PrismaProvider.initialized) {
      PrismaProvider.initialized = true
      await this.$connect()
    }
  }

  async onModuleDestroy() {
    if (PrismaProvider.initialized) {
      PrismaProvider.initialized = false
      await this.$disconnect()
    }
  }

  withExtensions() {
    return this.$extends(existsExtension)
      .$extends(softDeleteExtension)
      .$extends(findAndCountExtension)
  }
}

prisma.service.ts

import { Injectable, Type } from '@nestjs/common'
import { PrismaProvider } from './prisma.provider'

const ExtendedPrismaClient = class {
  constructor(provider: PrismaProvider) {
    return provider.withExtensions()
  }
} as Type<ReturnType<PrismaProvider['withExtensions']>>

@Injectable()
export class PrismaService extends ExtendedPrismaClient {
  constructor(provider: PrismaProvider) {
    super(provider)
  }
}

prisma.module.ts - @Global decorator give us ability to import PrismaModule once and make it available in any other module

import { Global, Module } from '@nestjs/common'
import { PrismaService } from './prisma.service'
import { PrismaProvider } from './prisma.provider'

@Global()
@Module({
  providers: [PrismaProvider, PrismaService],
  exports: [PrismaProvider, PrismaService],
})
export class PrismaModule {}

app.module.ts - don't forget to import PrismaModule here to make it app-wide

import { PrismaModule } from './prisma/prisma.module'
...
@Module({
  imports: [
    PrismaModule,
...