@ssdev-toolkit/nestjs-persistence
v1.0.0
Published
Prisma + Redis infrastructure: `DatabaseModule`, CRUD repository base, cache, locking port.
Readme
@ssdev-toolkit/nestjs-persistence
Prisma + Redis infrastructure: DatabaseModule, CRUD repository base, cache, locking port.
Install
npm install @ssdev-toolkit/nestjs-core @ssdev-toolkit/nestjs-persistenceThe host owns the generated Prisma client, connection string, and Redis URL.
What it does
DatabaseModule.forRoot/forRootAsync— wraps the hostPrismaClient, Keyv Redis cache.PrismaCrudRepositoryBase— required base for standard CRUD adapters (findPaged,create,update,delete,countcome from the base).PrismaRepositoryBase— custom / multi-model /$queryRawadapters.CacheService,@Cacheable,ILockingPort, mapper helpers.
Usage
DatabaseModule.forRootAsync({
useFactory: () => ({
redisUrl: process.env.REDIS_URL!,
prismaClientFactory: () => new PrismaClient(),
}),
});@Injectable()
export class RolePrismaRepository extends PrismaCrudRepositoryBase<
PrismaClient, 'authRole', Role, string, RoleFilter,
RoleRow, AuthRoleWhereInput, AuthRoleWhereUniqueInput,
AuthRoleCreateInput, AuthRoleUpdateInput, AuthRoleOrderByWithRelationInput
> implements IRoleRepository {
constructor(database: BasePrismaService<PrismaClient>) {
super(database, 'authRole'); // generated client key only
}
}Provide { provide: ICACHE_PORT, useExisting: CacheService } so auth and other modules can cache.
Build (this repo)
npm run build -w @ssdev-toolkit/nestjs-persistenceOverview: root README.
