3

I have a single instance prisma but it's not auto-completing any queries.

const { PrismaClient } = require("@prisma/client");
let prisma;
if (process.env.NODE_ENV === "production") {
  prisma = new PrismaClient();
  prisma.$connect();
} else {
  if (!global.__db) {
    global.__db = new PrismaClient();
    global.__db.$connect();
  }
  prisma = global.__db;
}
module.exports = prisma;

How can I get autocomplete intellisense 🤷🏻‍♂️?

4 Answers 4

7

Worked for me to generate the schemas for the prisma-client

You should have defined in your schema.prisma the generator:

// datasource here

generator client {
    provider = "prisma-client-js"
}

// your models here

Then run:

npx prisma generate

This reads your schema definition and generates a version of PrismaClient with all the intellisense related to your models. This command must be executed every time you update your models definition.

The process is described here.

7

I was using VSCode and intellisense for prisma was not working either, even after generating the schema. Restarting VSCode solved it for me. Just reopening the script might solve it too.

1

./prisma/prisma-client-js.js

const { PrismaClient } = require("@prisma/client");

class Db extends PrismaClient {
    static instance;
    constructor(){
        if(!Db.instance){
            Db.instance = new PrismaClient()
        }
        return Db.instance;
    }
}

module.exports = Db;

index.js

const Db = require('./prisma/prisma-client-js')
const dn = new Db();

This worked for me

0

Seems like you are using Javascript. The way I was able to get Intellisense autocomplete is by using Typescript and defining the prisma variable as follow: let prisma: PrismaClient; if I remember correctly.

I think the Prisma extension for VSCode also includes some Intellisense autocomplete if I am correct.

2
  • I have that extension but not working as expected :')
    – Robbi
    Commented May 4, 2022 at 17:42
  • @Robbi did you try using type definitions?
    – loom
    Commented May 4, 2022 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.