@sodacore/prisma
Version:
Sodacore Prisma is a plugin that initialises the Prisma ORM within your project.
44 lines (43 loc) • 1.97 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { BaseService, Service } from '@sodacore/core';
import { Registry } from '@sodacore/registry';
import PrismaClient from '../export/prisma';
import { Inject } from '@sodacore/di';
let PrismaService = class PrismaService extends BaseService {
async init() {
this.logger.info('[PRISMA]: Initialising the prisma client.');
this.prisma = new PrismaClient();
if (this.config && this.config.onInit) {
await this.config.onInit(this.prisma);
}
Registry.set(PrismaClient.name, this.prisma);
}
async start() {
if (!this.prisma)
throw new Error('Prisma client not initialised.');
this.logger.info('[PRISMA]: Starting the prisma client.');
await this.prisma?.$connect();
}
async stop() {
if (!this.prisma)
throw new Error('Prisma client not initialised.');
this.logger.info('[PRISMA]: Stopping the prisma client.');
await this.prisma?.$disconnect();
}
};
__decorate([
Inject('@prisma:config'),
__metadata("design:type", Object)
], PrismaService.prototype, "config", void 0);
PrismaService = __decorate([
Service()
], PrismaService);
export default PrismaService;