Overview

Prisma Client is an auto-generated and type-safe query builder that's tailored to your data. The easiest way to get started with Prisma Client is by following the Quickstart.

Quickstart (5 min)

The setup instructions below provide a high-level overview of the steps needed to set up Prisma Client. If you want to get started using Prisma Client with your own database, follow one of these guides:

Set up a new project from scratch

Add Prisma to an existing project

Set up

1. Prerequisites

In order to set up Prisma Client, you need a Prisma schema file with your database connection, the Prisma Client generator, and at least one model:

datasource db {
url = env("DATABASE_URL")
provider = "postgresql"
}
generator client {
provider = "prisma-client-js"
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
name String?
}

Also make sure to install the Prisma CLI:

npm install @prisma/cli --save-dev
npx prisma

2. Installation

You can install Prisma Client in your project with this command:

npm install @prisma/client

Note that this command also run the prisma generate command which generates the Prisma Client into the node_modules/@prisma/client directory.

3. Use Prisma Client to send queries to your database

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
// use `prisma` in your application to read and write data in your DB

or

const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
// use `prisma` in your application to read and write data in your DB

Once you have instantiated PrismaClient, you can start sending queries in your code:

// run inside `async` function
const newUser = await prisma.user.create({
data: {
name: 'Alice',
email: 'alice@prisma.io',
},
})
const users = await prisma.user.findMany()

4. Evolving your application

Whenever you make changes to your database that are reflected in the Prisma schema, you need to manually re-generate Prisma Client to update the generated code in the node_modules/@prisma/client directory:

prisma generate

In this section

Edit this page on Github