Tyler C
08/11/2022, 7:31 PMRaphael Etim
08/11/2022, 7:40 PMprisma generate
to generate the client? Also did you create an instance of the Prisma client?Tyler C
08/11/2022, 7:46 PMnpx prisma generate
Raphael Etim
08/11/2022, 8:02 PMTyler C
08/11/2022, 8:40 PMimport { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
});
}
}
Tyler C
08/11/2022, 8:41 PMTyler C
08/11/2022, 8:41 PMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
username String @unique
isAdmin Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Todo Todo[]
}
model Todo {
id Int @id @default(autoincrement())
title String
description String
isCompleted Boolean @default(false)
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade)
ownerId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Tyler C
08/11/2022, 8:43 PMTyler C
08/11/2022, 8:45 PMRaphael Etim
08/11/2022, 8:53 PMRaphael Etim
08/11/2022, 9:20 PMprisma.service.ts
file, You need to
import { PrismaClient } from '@prisma/client'
The Prisma
you imported is not a constructor function.Raphael Etim
08/11/2022, 9:24 PMuser.service.ts
file and i can get the autocompletion from vscode.Raphael Etim
08/11/2022, 9:24 PMTyler C
08/11/2022, 10:29 PMTyler C
08/11/2022, 11:39 PMRaphael Etim
08/12/2022, 4:20 AM