Install Prisma Client
Install and generate Prisma Client
To get started with Prisma Client, you need to install the @prisma/client
package:
npm install @prisma/client
You can now import the PrismaClient
constructor from the @prisma/client
package to create an instance of Prisma Client to send queries to your database. You'll learn how to do that in the next section.
The @prisma/client
npm package that was created in your node_modules
is a special library compared to other npm libraries.
Usually, the code of an npm package is downloaded in your project from the npm registry and is only updated when you explicitly call npm install
again. The @prisma/client
npm package is different!
It contains code (TypeScript types, methods, queries, ...) that is tailored to your Prisma schema file in prisma/schema.prisma
. This means, that whenever you make changes to your Prisma schema file, you also need to update the @prisma/client
folder inside node_modules
.
However, instead of doing this using an npm install
as with other npm packages, you can do this by running the prisma generate
command, which reads your Prisma schema and generates a version of Prisma Client that is tailored to your models:
Whenever you update your Prisma schema, you will have to update your database schema using either prisma migrate dev
or prisma db push
. This will keep your database schema in sync with your Prisma schema. The commands will also regenerate Prisma Client.
Install the Prisma Accelerate extension
Since Prisma Postgres provides a connection pool and (optional) caching layer with Prisma Accelerate, you need to install the Accelerate Client extension in your project as well:
npm install @prisma/extension-accelerate
With that you're all set to read and write data in your database. Move on to the next page to start querying your Prisma Postgres database using Prisma Client.