DEV Community

Shashank Trivedi
Shashank Trivedi

Posted on

Prisma ORM

1- Install Prisma: If you haven't installed Prisma yet, run the following commands to install it:

npm install prisma --save-dev
npx prisma init
Enter fullscreen mode Exit fullscreen mode

2- Update the prisma/schema.prisma file:

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
Enter fullscreen mode Exit fullscreen mode

3- Set the correct DATABASE_URL in your .env file, such as:

DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
Enter fullscreen mode Exit fullscreen mode

4- To generate prisma modal from existing tables

npx prisma db pull


/* This command will introspect the existing database and
automatically generate models in the `prisma/schema.prisma` file
based on the structure of your tables. */
Enter fullscreen mode Exit fullscreen mode

5- Once the introspection is done, you can generate Prisma Client to interact with your database.

npx prisma generate
Enter fullscreen mode Exit fullscreen mode

Top comments (0)