DEV Community

Cover image for Using Prettier with Prisma.io (pre-commit config)
imrinzzzz
imrinzzzz

Posted on

4

Using Prettier with Prisma.io (pre-commit config)

Cover photo by Anton Ivanov on Unsplash


If you're not familiar with prisma.io, it's an awesome ORM for Node.js. And in case if you don't know what an ORM (aka object-relational mapping) is, check out this stackoverflow thread for a comprehensive answer 😉.

Get started

Ok, let's get started. In one project of mine, I used node.js to develop a backend application for my app. I also used postgresql (which was why this article was created). In order for my app to communicate with the database, I used prima as an ORM.

Now, the problem was that I want the pre-commit config to check the format of **.prisma file(s). Luckily, someone made a prettier plugin for us.

  • First, add a dependency to your project
yarn add -D prettier-plugin-prisma
Enter fullscreen mode Exit fullscreen mode
  • To format the **.prisma file using CLI, run
yarn prettier --write "**/*.prisma"
Enter fullscreen mode Exit fullscreen mode
  • If you use vscode, you can edit the setting in settings.json to format the **.prisma on save
"editor.formatOnSave": true, 
"[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[prisma]": {
    "editor.defaultFormatter": "Prisma.prisma"
},
Enter fullscreen mode Exit fullscreen mode
  • Lastly, here's how my .pre-commit-config.yaml file looks like:
- repo: https://github.com/pre-commit/mirrors-prettier
  rev: v2.3.2 # Use the sha or tag you want to point at
  hooks:
    - id: prettier
      additional_dependencies:
        - prettier@2.1.2
        - 'prettier-plugin-prisma@2.29.1'

- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v3.4.0
  hooks:
  - id: trailing-whitespace
  - id: check-merge-conflict
  - id: check-yaml
  - id: end-of-file-fixer
  - id: no-commit-to-branch
    args: [-b, main, -b, production, -b, staging]
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay