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.

Samson Amaugo 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

dataloaders
Hello guys, have you been in a situation that looks …

Speeding up with data loaders

Using Cloud Firestore in Blazor WebAssembly
Hi, guys in this tutorial, you would learn how to …

Using Cloud Firestore in Blazor WebAssembly

About The Author

Samson Amaugo

I am Samson Amaugo. I am a full-stack developer and I specialize in DotNet and the MERN stack.

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

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#

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

  • Running Entity Framework Migrations in an Aspire-Bootstrapped Orleans Project
  • Using XDebug in Laravel Sail (VSCODE)
  • Custom Redis Streams Provider for Orleans
  • Creating a Custom File Storage Provider for Microsoft Orleans
  • Incremental Generators In C#
  • Hot Chocolate Data Loader: A Quick Guide
  • Exploring Policy-Based Authorization in Minimal API with .NET 8
  • Using Cloud Firestore in Blazor WebAssembly
  • Serving A VueJs App from DotNet
  • Dynamic Subscriptions in Hot Chocolate 🔥🍫

Swacblooms🦋

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