New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

prisma-libs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-libs

Prisma schema and migrations for database management

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Prisma Libs

A modern, type-safe database library built with Prisma ORM. This package provides a clean and intuitive API for database operations with full TypeScript support.

Features

  • 🚀 Latest Prisma Version: Built with Prisma 5.10.0
  • 🔒 Type Safety: Full TypeScript support with generated types
  • 🛠️ Utility Functions: Pre-built CRUD operations for common use cases
  • 🔄 Database Migrations: Easy database schema management
  • 🌱 Seeding: Built-in database seeding for development
  • 📊 Health Checks: Database connection monitoring
  • 🛑 Graceful Shutdown: Proper cleanup on application termination

Installation

npm install prisma-libs

Quick Start

1. Set up your database

Create a .env file in your project root:

DATABASE_URL="postgresql://username:password@localhost:5432/your_database_name"

2. Generate Prisma client

npx prisma generate

3. Push your schema to the database

npx prisma db push

4. Use in your code

import { prisma, userUtils, postUtils, connectDatabase } from 'prisma-libs';

async function main() {
  // Connect to database
  await connectDatabase();

  // Create a user
  const user = await userUtils.createUser('john@example.com', 'John Doe');
  console.log('Created user:', user);

  // Create a post
  const post = await postUtils.createPost(
    'My First Post',
    'This is the content of my first post.',
    user.id,
    true
  );
  console.log('Created post:', post);

  // Find user with posts
  const userWithPosts = await userUtils.findUserById(user.id);
  console.log('User with posts:', userWithPosts);
}

main().catch(console.error);

API Reference

Core Exports

  • prisma: Singleton Prisma client instance
  • PrismaClient: Prisma client class
  • User, Post: Generated TypeScript types

Database Management

import { connectDatabase, disconnectDatabase, healthCheck } from 'prisma-libs';

// Connect to database
await connectDatabase();

// Check database health
const isHealthy = await healthCheck();

// Disconnect from database
await disconnectDatabase();

User Operations

import { userUtils } from 'prisma-libs';

// Create a new user
const user = await userUtils.createUser('email@example.com', 'User Name');

// Find user by email
const user = await userUtils.findUserByEmail('email@example.com');

// Find user by ID (includes posts)
const user = await userUtils.findUserById('user-id');

// Update user
const updatedUser = await userUtils.updateUser('user-id', {
  name: 'New Name',
  email: 'newemail@example.com'
});

// Delete user
await userUtils.deleteUser('user-id');

// Get all users
const users = await userUtils.getAllUsers();

Post Operations

import { postUtils } from 'prisma-libs';

// Create a new post
const post = await postUtils.createPost(
  'Post Title',
  'Post content',
  'author-user-id',
  true // published
);

// Find post by ID (includes author)
const post = await postUtils.findPostById('post-id');

// Find posts by author
const posts = await postUtils.findPostsByAuthor('author-user-id');

// Update post
const updatedPost = await postUtils.updatePost('post-id', {
  title: 'New Title',
  published: true
});

// Delete post
await postUtils.deletePost('post-id');

// Get all posts
const posts = await postUtils.getAllPosts();

// Get only published posts
const publishedPosts = await postUtils.getPublishedPosts();

Graceful Shutdown

import { setupGracefulShutdown } from 'prisma-libs';

// Set up graceful shutdown handlers
setupGracefulShutdown();

Database Schema

The package includes a sample schema with User and Post models:

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  posts Post[]

  @@map("users")
}

model Post {
  id        String   @id @default(cuid())
  title     String
  content   String?
  published Boolean  @default(false)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  author   User   @relation(fields: [authorId], references: [id], onDelete: Cascade)
  authorId String

  @@map("posts")
}

Development

Prerequisites

  • Node.js 18 or higher
  • PostgreSQL database
  • npm or yarn

Setup

  • Clone the repository
  • Install dependencies: npm install
  • Copy env.example to .env and configure your database URL
  • Generate Prisma client: npm run generate
  • Push schema to database: npm run db:push
  • Seed database: npm run db:seed

Available Scripts

  • npm run build - Build the TypeScript code
  • npm run dev - Watch mode for development
  • npm run generate - Generate Prisma client
  • npm run db:push - Push schema changes to database
  • npm run db:migrate - Create and apply migrations
  • npm run db:studio - Open Prisma Studio
  • npm run db:seed - Seed the database with sample data

Contributing

  • Fork the repository
  • Create a feature branch
  • Make your changes
  • Add tests if applicable
  • Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions, please open an issue on GitHub. # prisma-libs

FAQs

Package last updated on 01 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts