Swacblooms

Making the Moves
Menu
  • Home
  • Motivation
  • Education
  • Programming
  • About
  • Contact
  • Privacy Policy
Home
Programming
Manipulating the Prisma Schema Using Regex.
Programming

Manipulating the Prisma Schema Using Regex.

Sammy June 16, 2020

Hello guys, so in this post, I would be writing about using regex to manipulate the Prisma schema file.

It all started by seeing a complaint on adjusting the fields in a schema file from snake_case to camel_case.

Well, the reason behind this is that in your SQL tables, you might have a column with the title, “first_name” and after running the Prisma introspect command you would see a field with the title, “first_name” in your schema file.

You might not really want to use that to query your database with the Prisma client API. So rather than doing that, you can make the API to use something else of preference, for instance, “firstName” with the help of the “@map” attribute for fields and “@@map” attribute for models.

You can see what I want to convert in the code below:-

So I wrote a small script that converts a Prisma schema file from using snake case models or fields to using camel case.

After writing this script, I showed it to one of my friends, Ahmed, he has created various Prisma tools including a CLI tool that converts your schema file from using snake-case models and fields to using camel-case. He told me that it won’t satisfy all cases and he listed the extra cases that I should implement. At the end of the post, I would leave a link to his Prisma tools.

He told me it won’t satisfy cases like “users_posts Post[] @relation(fields:[user_id, user_name])”

So I went further to make adjustments to the script and came up with this.

Thanks for reading and you can check out his awesome tools here. I highly recommend you use his tool if you need to integrate it into your build chain as this post is mainly to give insight on what the code could look like.

I decided to create a vs-code plugin that performs this function. You can check it out here

Prev Article
Next Article

Related Articles

Search and Replace
Perform a search and replace on the sentence using the …

Search and Replace

reactive variables(apollo client)
Hello guys, in this tutorial, I would be talking about …

Reactive Variables

About The Author

Sammy

I am Samson Amaugo. I am a full-stack web developer and I specialize in MERN stack development

2 Comments

  1. Ralph

    Boss man. Do you have docker

    June 16, 2020
    • Sammy

      Yes I do bro

      June 16, 2020

Leave a Reply

Cancel reply

Search Site

Recent Posts

  • Easy SSH Via Local DNS
  • Sshing into your computer from anywhere in the world
  • Case Statement: Ruby
  • Voucher Based Ethereum System
  • Making a CRUD API using Azure Functions

Categories

  • EDUCATION
  • Motivation
  • Programming
  • Uncategorized

Get more stuff

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

we respect your privacy and take protecting it seriously

RSS Swacblooms

  • Easy SSH Via Local DNS
  • Sshing into your computer from anywhere in the world
  • Case Statement: Ruby
  • Voucher Based Ethereum System
  • Making a CRUD API using Azure Functions
  • Making a Wikipedia chatbot with WIT.AI
  • Making a small Library in Solidity
  • Fauna+Azure Functions
  • MLH Fellowship (Major League Hacking)
  • GraphQL Basic Overview

Swacblooms

Making the Moves
Copyright © 2021 Swacblooms
Swacblooms - Making the Moves