'Single instance Prisma client autocomplete not working
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 🤷🏻♂️?
Solution 1:[1]
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.
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | svex99 |
Solution 2 | DharmanBot |