⚠️ This lesson is retired and might contain outdated information.

Generate type safe client with prisma

Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

In this lesson you will learn how to generate type safe orm client with prisma generate and do first write operation using it.

Dimitri Ivashchuk: [0:00] We can now move on with Prisma client. Let's yarn add @prisma/client, which downloads the so-called "smart node module," which is an empty module, filled with the command npx prisma generate.

[0:18] It puts into the Prisma client all the things picked up from the schema.prisma, which gives you TypeScript definitions, autocompletion, and all the nice features for Prisma as an ORM. Let's try to run this command.

[0:40] It has been successfully generated. Let's write some simple queries with Prisma client. Let's create the index.ts and add some boilerplate Prisma. We import our generated client, instantiate the new one, and here we want to write our first Prisma operation, which will write something into our database, and then execute this function later.

[1:17] Let's write our first Prisma function, and for that we need to call Prisma. You see that in the methods and properties, we already have users autocompleted for us. We go for that.

[1:31] Then we want to go for create method and we want to pass data with the name, which again is autocompleted, dimitri. Of course, we want to await this.

[1:47] To run this function, we need to execute npx ts-node index.ts. It has been successfully executed. Now we can go directly to psql prisma postgres and just try to lock the users stable. Select * from users. You see that we have our first table entry with id 1 and name dimitri, which we have now provided to Prisma.

egghead
egghead
~ 27 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today