ORMs and Why I Recommend Prisma

I’ll just leave this here…

What’s the benefit of using an ORM?

The biggest advantage that you get out of implementing an ORM is that you get to write your queries comfortably in the language of your choice. This minimizes the constraints you have in terms of development tremendously. For someone like me who absolutely detests query languages, ORM adds a lot of flexibility in terms of the usage of database(s) as well. Moreover, you can easily reuse your code with minor to no changes.

What is Prisma?

  1. Prisma Migrate: A service that automatically generates SQL database migrations, that are fully customizable. For quick data model prototyping in development,prisma db push lets you make changes to the database without generating migration files.
  2. Prisma Studio: A visual database browser that opens in your browser to graphically view and edit the data.

How does it work?

Every project that uses a tool from the Prisma toolkit starts with a Prisma schema file. This Prisma schema file is the main configuration file for your Prisma setup. It is typically called schema.prisma and consists of Data Sources, Generators, and Data Model Definition. It allows developers to define their application models in an intuitive data modeling language. Whenever a prisma command is invoked, the CLI typically reads some information from the schema file, which contains the connection to a database and defines a generator.

Installing Prisma

  1. In order to get started, we’ll install the Prisma CLI tool as a development dependency using npm install —-dev prisma.
  2. Now we’ll set up our Prisma project by creating the Prisma schema file template with npx prisma init. This creates a /prismafolder with a schema.prisma file at the root of the project. There’s also new /.env that you should add to .gitignore.
  3. To connect your database, you need to set the url field of the datasource block in your Prisma schema to your database connection URL. The format of the connection URL for your database depends on the database you use.
  4. With the npx prisma db pullcommand, Prisma can pull the pre-existing database schema and on its own copy and refactor it into the schema.prisma file. Alternatively, you can also install and generate Prisma Client. Simply run npm install @prisma/client, followed by npx prisma generate. This command reads your Prisma schema and generates your Prisma Client library.

Why Prisma?

Ending Notes

ORM is advantageous for the folks who have a stronger background in OOPs and not SQL or query languages. Only consider implementing this system if you’re ready to learn more about the ORM library, what it offers and how to set it up error-free, otherwise, you might end up wasting your time instead of trying to save it. Even if you dive into ORM, continue to practice and have a good hold over SQL and other query languages.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aaishika S Bhattacharya

Aaishika S Bhattacharya

Jr. Developer Advocate @ DigitalOcean | GitHub Campus Expert & Stream Team | GDSC ‘22 & Hack Club Lead | Alexa Student Influencer | Ex- MLH Coach