Course

Prisma Client

The is an auto-generated and type-safe query builder that's tailored to your data. Prisma will generate a client for you based on your Prisma schema. This client will allow you to interact with your database in a type-safe way- including autocomplete and type checking!

Generating the Prisma Client

To generate the Prisma Client, you can run the following command:

npx prisma generate

This command will generate a Prisma Client in the directory. The generated client is used in your code and provides you with a type-safe way to interact with your database. You can then import the Prisma Client in your code and start using it to interact with your database.

Whenever you make changes to your Prisma schema, you will need to regenerate the Prisma Client to reflect those changes.

Exporting the Prisma Client

Let's create a file to export our Prisma Client instance. We will create a new file called prisma.ts in the directory.

prisma.ts;

export const prisma = new PrismaClient();

Using the Prisma Client

Later, you can import this Prisma Client in your code and start using it to interact with your database.

some - server - action - file.ts;

// use 'prisma' to interact with your database
// to create, read, update, or delete data

Our generated a property for each model defined in the Prisma schema. So we have access to the:

property to interact with the Product model

property to interact with the Image model

property to interact with the Review model

Each of these properties provides methods that allow us to interact with the corresponding model in the database. Some of the most common methods provided by the Prisma Client include:

: Create a new record in the database

: Find a single record by its unique identifier

: Find multiple records that match a given query

: Update an existing record in the database

: Delete a record from the database

In the next lesson, we'll import this Prisma Client and use it to interact with our database.

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

Building A Server Action: Create a Product