@tsed/cli
Version:
CLI to bootstrap your Ts.ED project
25 lines (22 loc) • 708 B
JavaScript
import { defineTemplate } from "../utils/defineTemplate.js";
export default defineTemplate({
id: "prisma.service",
label: "Prisma Service",
description: "Generate a service based on PrismaClient with $onInit/$onDestroy hooks to manage the database connection.",
fileName: "prisma.service",
outputDir: "{{srcDir}}/services",
render(symbolName) {
return `import { Injectable, OnInit, OnDestroy } from "@tsed/di";
import { PrismaClient } from "@prisma/client";
@Injectable()
export class ${symbolName} extends PrismaClient implements OnInit, OnDestroy {
async $onInit() {
await this.$connect();
}
async $onDestroy() {
await this.$disconnect();
}
}
`;
}
});