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

React-ref callback
Okay guys this is a continuation of the previous react …

React- Callback Refs

looking for a nice training platform
Have you thought about starting a blog and lost in …

Blogging And Some Tips

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

  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫
  • Deploying a DotNet API To Railway 🚂
  • GitHub OAuth Device Flow in DotNet

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

  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫
  • Deploying a DotNet API To Railway 🚂
  • GitHub OAuth Device Flow in DotNet
  • Resumable Download in DotNet
  • Mocking the HttpClient in C#
  • MySocials DotNet CLI Tool
  • Benchmarking in C#
  • C# bang bang operator

Swacblooms🦋

Making the Moves
Copyright © 2023 Swacblooms🦋
Swacblooms - Making the Moves