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

@nathapp/nestjs-prisma

v3.3.0

Published

NestJS Prisma integration with multi-database support

Readme

@nathapp/nestjs-prisma

Prisma 6 wrapper for NestJS with multi-database support, transactions, an IRepository-compatible abstract repository, pagination, and error mapping.

Installation

npm install @nathapp/nestjs-prisma

@prisma/client is a peer dependency — install it in your consuming app; you will also want the prisma CLI installed there for migrations. This package is part of the @nathapp/nestjs-* peer-layer stack and builds on @nathapp/nestjs-common and @nathapp/nestjs-data.

What it provides

  • PrismaModuleforRoot({ client, name?, transaction?, isGlobal? }) / forRootAsync({ useFactory | useClass | useExisting }). Repeat the call with different name values to register multiple databases.
  • PrismaService — wraps a PrismaClient instance (composition, not inheritance) for multi-DB flexibility; exposes .client and .isConnected.
  • AbstractPrismaRepository<TDomain, TModel, TId> — implements IRepository<TDomain, TId> from @nathapp/nestjs-data. Subclasses implement modelDelegate, toDomain, toPersistenceCreate, toPersistenceUpdate.
  • InjectPrisma(name?) — parameter decorator to inject a named PrismaService.
  • PrismaHealthIndicatorisHealthy() returns { status: 'up' | 'down' }.
  • Paginate(model, pageOption, args?) — paginate a raw Prisma model query, returning a Page<T> from @nathapp/nestjs-common.
  • PrismaExceptionFilter@Catch filter mapping PrismaClientKnownRequestError / PrismaClientValidationError to a standardized error response.
  • PrismaErrorMapper, PRISMA_ERROR_CODES — map known Prisma error codes (P2000, P2002, P2003, P2025, ...) to an AppException with a string code.
  • getPrismaToken(name?), getPrismaTransactionManagerToken(name?) — derive the DI tokens for a named connection's PrismaService / ITransactionManager.
  • Prisma testing utilities under the testing export.

Usage

Single-DB setup and a repository implementation:

import { Module, Inject, Injectable } from '@nestjs/common';
import { PrismaModule, AbstractPrismaRepository } from '@nathapp/nestjs-prisma';
import { TRANSACTION_MANAGER, ITransactionManager, IRepository } from '@nathapp/nestjs-data';
import { PrismaClient } from '@prisma/client';

interface User { id: string; email: string; name: string }

@Injectable()
export class PrismaUserRepository extends AbstractPrismaRepository<User, any, string> {
  constructor(@Inject(TRANSACTION_MANAGER) tx: ITransactionManager) { super(tx); }
  protected modelDelegate(client: any) { return client.user; }
  protected toDomain(m: any): User { return { id: m.id, email: m.emailAddress, name: m.fullName }; }
  protected toPersistenceCreate(d: User) { return { id: d.id, emailAddress: d.email, fullName: d.name }; }
  protected toPersistenceUpdate(p: Partial<User>) {
    const out: any = {};
    if (p.email !== undefined) out.emailAddress = p.email;
    if (p.name !== undefined) out.fullName = p.name;
    return out;
  }
}

export const USER_REPOSITORY = Symbol('USER_REPOSITORY');

@Module({
  imports: [PrismaModule.forRoot({ client: PrismaClient, transaction: true })],
  providers: [
    PrismaUserRepository,
    { provide: USER_REPOSITORY, useExisting: PrismaUserRepository },
  ],
})
export class AppModule {}

Multi-DB and transactions

For multiple databases in one process, call PrismaModule.forRoot once per connection with a distinct name, and inject the connection-scoped tokens returned by getPrismaToken(name) / getPrismaTransactionManagerToken(name) instead of the default PrismaService / TRANSACTION_MANAGER. Only the default connection aliases the global TRANSACTION_MANAGER symbol from @nathapp/nestjs-data. A tx.run() on a named transaction manager covers only that connection's writes — there is no cross-DB atomicity; use sagas or an outbox pattern for cross-DB consistency.