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

@natiwo/database

v0.1.0

Published

NATIWO Database - Prisma, DynamoDB e Redis helpers

Readme

@natiwo/database

Database clients for Prisma, DynamoDB, and Redis

npm version

Installation

pnpm add @natiwo/database

# Install peer dependencies as needed
pnpm add @prisma/client      # For Prisma
pnpm add @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb  # For DynamoDB
pnpm add ioredis             # For Redis

Features

  • 🗄️ Prisma Client - Singleton instance with connection pooling
  • ☁️ DynamoDB - Type-safe repository pattern
  • Redis - Caching with decorators
  • 🔄 Auto-reconnect - Handles connection failures
  • 📊 TypeScript - Full type safety

Quick Start

Prisma

import { getPrismaClient } from '@natiwo/database';

const prisma = getPrismaClient();

const users = await prisma.user.findMany();
const user = await prisma.user.create({
  data: {
    email: '[email protected]',
    name: 'John Doe',
  },
});

DynamoDB

import { DynamoRepository } from '@natiwo/database';

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

const userRepo = new DynamoRepository<User>('users-table');

// Get item
const user = await userRepo.get({ id: '123' });

// Put item
await userRepo.put({
  id: '123',
  email: '[email protected]',
  name: 'John Doe',
});

// Query
const users = await userRepo.query({
  keyCondition: 'email = :email',
  values: { ':email': '[email protected]' },
});

// Scan
const allUsers = await userRepo.scan();

// Update
await userRepo.update({
  key: { id: '123' },
  updates: { name: 'Jane Doe' },
});

// Delete
await userRepo.delete({ id: '123' });

Redis

import { getRedisClient, Cache } from '@natiwo/database';

const redis = getRedisClient();

// Basic operations
await redis.set('key', 'value');
const value = await redis.get('key');
await redis.del('key');

// With expiration
await redis.setex('key', 3600, 'value'); // Expires in 1 hour

// Cache decorator
class UserService {
  @Cache(600) // Cache for 10 minutes
  async getUser(id: string) {
    return await prisma.user.findUnique({ where: { id } });
  }
}

Configuration

Prisma

Uses DATABASE_URL environment variable:

DATABASE_URL="postgresql://user:password@localhost:5432/mydb"

DynamoDB

Configure AWS credentials:

AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-key
AWS_SECRET_ACCESS_KEY=your-secret

Or use custom config:

import { getDynamoClient } from '@natiwo/database';

const dynamo = getDynamoClient({
  region: 'us-east-1',
  endpoint: 'http://localhost:8000', // For local DynamoDB
});

Redis

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your-password
REDIS_DB=0

Or programmatic:

import { getRedisClient } from '@natiwo/database';

const redis = getRedisClient({
  host: 'localhost',
  port: 6379,
  password: 'secret',
});

Advanced Usage

Prisma Transaction

const result = await prisma.$transaction([
  prisma.user.create({ data: userData }),
  prisma.profile.create({ data: profileData }),
]);

DynamoDB Batch Operations

const userRepo = new DynamoRepository<User>('users');

// Batch write
await Promise.all([
  userRepo.put(user1),
  userRepo.put(user2),
  userRepo.put(user3),
]);

Redis Caching Pattern

async function getCachedUser(id: string) {
  const cached = await redis.get(`user:${id}`);
  
  if (cached) {
    return JSON.parse(cached);
  }
  
  const user = await prisma.user.findUnique({ where: { id } });
  await redis.setex(`user:${id}`, 3600, JSON.stringify(user));
  
  return user;
}

Best Practices

  1. Reuse client instances

    // ✅ Good - single instance
    const prisma = getPrismaClient();
       
    // ❌ Bad - creates new connections
    const prisma1 = new PrismaClient();
    const prisma2 = new PrismaClient();
  2. Handle errors gracefully

    try {
      await prisma.user.create({ data });
    } catch (error) {
      if (error.code === 'P2002') {
        // Unique constraint violation
      }
    }
  3. Use transactions for related operations

    await prisma.$transaction([
      prisma.account.update({ ... }),
      prisma.transaction.create({ ... }),
    ]);
  4. Close connections on shutdown

    process.on('SIGTERM', async () => {
      await prisma.$disconnect();
      await redis.quit();
      process.exit(0);
    });

License

MIT © NATIWO Sistemas