skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. ./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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search