DEV Community

Cover image for Don't write npx prisma generate command
Ashfiquzzaman Sajal
Ashfiquzzaman Sajal

Posted on

Don't write npx prisma generate command

I mean, don't write npx prisma generate command frequently. 😪😅

Don't ask "why" before reading the full post.

What's Prisma?

It's a tool that makes working with databases simple. Think of it as a translator between your code and your database, making sure everything's understood.

The "npx prisma generate" Command

This command takes your database schema (a blueprint of your data) and creates:

  • Prisma Client: A super-powered query builder that makes interacting with your database a breeze.
  • Types: Little helpers that tell your code what kind of data you're working with, preventing errors.

When to Use It

  • Initial Setup: Run it once to get started.
  • Schema Changes: Run it again whenever you change your database schema.
  • New Prisma Packages: Run it after installing new Prisma packages.

Automating Generation

Make your life even easier by automating this command with build tools like npm run build or yarn build. This ensures your generated code is always up-to-date.

Here's how:

  1. Add a script to your package.json file:

    {
      "scripts": {
        "build": "npx prisma generate && ... other build steps ..."
      }
    }
    
  2. Run the build script:

    npm run build
    

Now your code and database are in perfect harmony.

The "npx prisma generate" command is a powerful tool that makes your life easier. Use it wisely, and enjoy a smoother development experience!

🔥😎 Follow me in X/Twitter

Top comments (0)