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

@saas-packages/database-manager

v1.2.0

Published

Database manager for SaaS applications using Prisma (requires @prisma/client as peer dependency)

Readme

@saas-packages/database-manager

Database management for SaaS applications using Prisma.

Installation

npm install @saas-packages/database-manager @prisma/client

Note: This package requires @prisma/client as a peer dependency. Make sure to install it in your application.

Usage

This package expects you to provide your own PrismaClient instance from your application's schema.

1. Set up your Prisma schema in your application

// prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

// Your application models
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

2. Generate and use the PrismaClient with DatabaseManager

import { PrismaClient } from '@prisma/client';
import { DatabaseManager, DatabaseServiceProvider } from '@saas-packages/database-manager';
import { container } from 'tsyringe';

// Create your PrismaClient instance
const prisma = new PrismaClient();

// Simplified configuration - only requires the PrismaClient
const dbConfig = {
  prismaClient: prisma
};

const provider = new DatabaseServiceProvider(dbConfig);
provider.register(container);

// Resolve and use the database manager
const dbManager = container.resolve('database.manager');
await dbManager.connect();

// Use the database manager
const health = await dbManager.healthCheck();
console.log('Database health:', health);

// Access the PrismaClient directly
const users = await dbManager.client.user.findMany();

3. Using transactions

// Execute a transaction
const result = await dbManager.executeTransaction(async (prisma) => {
  const user = await prisma.user.create({
    data: {
      email: '[email protected]',
      name: 'John Doe'
    }
  });
  
  const profile = await prisma.profile.create({
    data: {
      userId: user.id,
      bio: 'Hello world'
    }
  });
  
  return { user, profile };
});

4. Health checking

const health = await dbManager.healthCheck();
if (health.status === 'healthy') {
  console.log(`Database is healthy. Latency: ${health.details.latency}ms`);
} else {
  console.error('Database is unhealthy:', health.error);
}

Configuration

The DatabaseManagerConfig interface has been simplified and now only requires:

  • prismaClient: Your PrismaClient instance

Configuration Changes

The configuration has been streamlined to focus on the essential requirement - the PrismaClient instance. Previous configuration options like url, logQueries, logErrors, etc. have been removed in favor of:

  1. Dependency Injection: The database manager now uses the core package's dependency injection system
  2. Logger Integration: Logging is now handled through the optional logger parameter in the service provider
  3. Simplified Setup: Only the PrismaClient instance is required in the configuration

Service Provider Pattern

The DatabaseServiceProvider registers the following services in the dependency container:

  • database.config: The database configuration
  • database.logger: The logger instance (if provided)
  • database.manager: The database manager singleton
  • DatabaseManager: The database manager class for direct instantiation

Integration with Queue Manager

When using both database and queue managers together:

import { PrismaClient } from '@prisma/client';
import { DatabaseManager, DatabaseServiceProvider } from '@saas-packages/database-manager';
import { QueueManager, QueueServiceProvider } from '@saas-packages/queue-manager';
import { container, Logger } from '@saas-packages/core';
import Redis from 'ioredis';

// Create instances
const prisma = new PrismaClient();
const redis = new Redis();
const logger = new Logger({ level: 'info' });

// Database configuration
const dbConfig = {
  prismaClient: prisma
};

// Queue configuration
const queueConfig = {
  connection: redis,
  defaultJobOptions: {
    attempts: 3,
    backoff: {
      type: 'exponential',
      delay: 2000
    }
  }
};

// Register both providers
const dbProvider = new DatabaseServiceProvider(dbConfig, logger);
const queueProvider = new QueueServiceProvider(queueConfig, logger);

dbProvider.register(container);
queueProvider.register(container);

// Use both managers
const dbManager = container.resolve('database.manager');
const queueManager = container.resolve('queue.manager');

await dbManager.connect();