When using `import {Prisma} from '@prisma/client'....
# orm-help
t
When using `import {Prisma} from '@prisma/client'. I am unable to see the types such as Prisma.UserWhereUniqueInput, etc. No autocompletion from VScode. Is there something I need to do in order to see these 'types' for my models. Thanks in advance.
1
r
Hi Tyler 👋 Did you run
prisma generate
to generate the client? Also did you create an instance of the Prisma client?
t
Hello Raphael, yes, I've generated the client by running
npx prisma generate
r
Can you please share a snippet of your client?
t
Copy code
import { 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();
    });
  }
}
^ this is the generic prismaService provider (taken from nestjs docs - the default one)
here is my prisma schema
Copy code
generator 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
}
and i've run the prisma generate commands, etc. This is me just trying to use the Prisma var and not seeing the Where's and Args I should see (as in the docs)
However, if I go into the node modules folder, I can see the types when I navigate to Prisma.
r
I'm trying to reproduce the issue you are facing. I'll get back to you on this.
💯 1
👍 1
Looking at the
prisma.service.ts
file, You need to
Copy code
import { PrismaClient } from '@prisma/client'
The
Prisma
you imported is not a constructor function.
I created a
user.service.ts
file and i can get the autocompletion from vscode.
t
Oh, I just out the Prisma. In that file for a photo. I've placed it in multiple providers such as my userService and todoService, but I guess maybe it's just my vscode then.
Just tried now, it works. Thank you @Raphael Etim
r
You are welcome Tyler. 🙏