prisma-super
v0.0.1
Published
A Prisma Client wrapper with caching, hooks, and enhanced query methods
Downloads
5
Maintainers
Readme
Prisma Wrapper
A Prisma Client wrapper that enhances the Prisma ORM with caching, hooks, and advanced query methods like pagination, soft deletes, and field exclusion.
Installation
npm install prisma-wrapperUsage
Initialize the Wrapper
import { PrismaClient } from '@prisma/client';
import { extendPrismaClient } from 'prisma-wrapper';
const prisma = new PrismaClient();
const db = extendPrismaClient(prisma, {
logger: console,
cacheTtl: 60000 // Cache TTL in milliseconds
});Setup Hooks
db.setupHooks('find', async (params) => {
console.log(`Querying ${params.model} with`, params);
});Paginated Query
const users = await db.user.findManyX({
where: { isActive: true },
exclude: ['password', 'token'],
paginate: { page: 2, pageSize: 5 },
orderBy: { createdAt: 'desc' },
transform: (user) => ({
...user,
isVIP: user.plan === 'premium',
fullName: `${user.firstName} ${user.lastName}`,
}),
});Find or Create
const user = await db.user.findOrCreateX({
where: { email: '[email protected]' },
create: { email: '[email protected]', name: 'Test User' },
});Soft Delete
await db.user.softDeleteX({ id: 1 });Features
- Caching: In-memory caching for query results with configurable TTL.
- Hooks: Pre/post query hooks for find, create, update, and soft delete operations.
- Pagination: Built-in support for paginated queries.
- Soft Deletes: Support for soft deletes with
deletedAtfield. - Field Exclusion: Exclude specific fields from query results.
- Transformations: Apply custom transformations to query results.
- Type Safety: Enhanced TypeScript support for better developer experience.
Requirements
- Node.js >= 18
- Prisma >= 5.0.0
License
MIT
