@alleen/prisma
v1.0.1
Published
Core NestJS module for alleen-api — dynamic multi-database Prisma registry
Readme
@alleen/prisma
⚠️ Important
This package cannot function on its own.
It is designed as a required dependency for alleen to work properly within a project.👉 To correctly initialize a compatible project, use the official repository:
https://github.com/olivierAdou/alleen-api.git
Base Prisma service for alleen-api — connection management, retry, health checks.
Tous les services générés par@alleen/cliétendent automatiquementBasePrismaService.
Installation
npm install @alleen/prismaCe que ça remplace
Avant @alleen/prisma, chaque service généré avait son propre code de connexion :
// ❌ Avant — dupliqué dans chaque service
async onModuleInit() { await this.$connect(); }
async onModuleDestroy() { await this.$disconnect(); }Après, le service généré fait juste :
// ✅ Après — 5 lignes, tout le reste est dans BasePrismaService
@Injectable()
export class PhoenixPrismaService extends BasePrismaService {
constructor() {
super('phoenix');
}
}BasePrismaService gère en interne :
- Connexion avec retry automatique (3 tentatives par défaut)
- Timeout de connexion configurable
- Déconnexion propre au shutdown
- Health check
SELECT 1par DB - Logging structuré par DB
Setup dans app.module.ts
import { AlleenPrismaModule } from '@alleen/prisma';
import { PhoenixPrismaService } from './prisma/phoenix.service';
import { BulkPrismaService } from './prisma/bulk.service';
@Module({
imports: [
AlleenPrismaModule.forRoot({
services: [PhoenixPrismaService, BulkPrismaService],
globalOptions: {
retryAttempts: 5,
retryDelay: 2000,
connectionTimeout: 15000,
verbose: false,
},
}),
],
})
export class AppModule {}Injection avec @InjectDb
Pour injecter une DB spécifique dans n'importe quel service :
import { Injectable } from '@nestjs/common';
import { InjectDb, BasePrismaService } from '@alleen/prisma';
@Injectable()
export class OrderService {
constructor(
@InjectDb('phoenix') private readonly db: BasePrismaService
) {}
async getOrders() {
return this.db.order.findMany({ where: { status: 'ACTIVE' } });
}
}Health checks
import { PrismaHealthService } from '@alleen/prisma';
@Controller('health')
export class HealthController {
constructor(private readonly health: PrismaHealthService) {}
@Get()
async check() {
return this.health.checkAll();
}
}Réponse :
{
"overall": "healthy",
"databases": [
{ "database": "phoenix", "status": "up", "latency": 4, "checkedAt": "..." },
{ "database": "bulk", "status": "up", "latency": 6, "checkedAt": "..." }
],
"checkedAt": "2026-04-05T10:00:00.000Z"
}overall vaut "healthy", "degraded" (certaines DBs down), ou "down" (toutes down).
Options de connexion
| Option | Type | Default | Description |
|---|---|---|---|
| retryAttempts | number | 3 | Tentatives avant d'abandonner |
| retryDelay | number | 3000 | Délai entre tentatives (ms) |
| connectionTimeout | number | 10000 | Timeout de connexion (ms) |
| verbose | boolean | false | Logs Prisma détaillés |
License
MIT © olivier adou
