Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prisma-case-format

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prisma-case-format

Give your introspected schema.prisma sane casing conventions

  • 1.4.0-beta.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

prisma-case-format

As of prisma@2.19.0, prisma introspect will name its model 1:1 with your database's conventions. That's great, but if your db is purely snake_case, or worse if your tables lack any common convention, it can make the autogenerated client code less pleasant to consume. prisma-case-format will format your prisma schema's model and field names to enforce a more conventional experience.

Use-case: as a one-time migration assistant

Use --dry-run to figure out which case conventions are correct for your project. Once things look correct, drop the flag to save changes to the --file (or your local schema.prisma by default).

Use-case: as a small CI/CD component

prisma-case-format now aims to be idempotent, so you can use it to confirm that case conventions in your schema.prisma have not accidentally drifted. prisma-case-format can be applied on-commit or on-push, either in a git commit-hook package or as a CI/CD step. Use --dry-run to diff changes with the original file, or backup the original and compare to the edit.

Usage

❯ prisma-case-format --help
Usage: prisma-case-format [options]

Give your schema.prisma sane naming conventions

Options:
  --file <file>                    cwd-relative path to schema.prisma file (default: "schema.prisma")
  -D, --dry-run                    print changes to console, rather than back to file (default: false)
  --table-case <tableCase>         case convention for table names (default: "pascal")
  --field-case <fieldCase>         case convention for field names (default: "camel")
  --map-table-case <mapTableCase>  case convention for @@map() annotations
  --map-field-case <mapFieldCase>  case convention for @map() annotations
  -p, --pluralize                  optionally pluralize array type fields (default: false)
  -V, --version                    hint: you have v1.3.0
  -h, --help                       display help for command
Supported case conventions: ["pascal", "camel", "snake"]

Example

// schema.prisma before
...
model house_rating {
  id       Int    @id @default(autoincrement())
  house_id String
  house    house  @relation(fields: [house_id], references: [id])
  ...
}
...
model house {
  id  String  @id @default(uuid())
  house_rating house_rating[]
  ...
}
...
❯ prisma-case-format
✨ Done.
// schema.prisma after
...
model HouseRating {
  id       Int    @id @default(autoincrement())
  houseId  String @map("house_id")
  house    House  @relation(fields: [houseId], references: [id])
  ...

  @@map("house_rating")
}
...
model House {
  id           String        @id @default(uuid())
  houseRating HouseRating[]
  ...

  @@map("house")
}
...

Supply the -p or --pluralize argument to get array pluralizations.

❯ prisma-case-format -p
✨ Done.
// schema.prisma after pluralization
...
model House {
  ...
  houseRatings HouseRating[]
  ownerContacts String[] @map("owner_contact")
  ...
}
...

FAQs

Package last updated on 08 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc