npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prisma-schema-transformer

v0.8.1

Published

Transform names from snake_case to camelCase in Prisma schema.

Downloads

56

Readme

prisma-schema-transformer

EXPERIMENTAL

This project utilizes the getDMMF method from @prisma/sdk to perform some post-processing work on generated Prisma schema, including the following.

  • Transform snake_case to camelCase,
  • Properly singularize or pluralize model and field name.
  • Add @updatedAt attribute to field in the event of column name is updated_at
  • Ignore models from the schema.

TODO

  • [ ] Auto generate the generator and datasource nodes.

Install

$ yarn global add prisma-schema-transformer

Usage

$ prisma-schema-transformer prisma/schema.prisma
Usage
  $ prisma-schema-transformer [options] [...args]

Specify a schema:
  $ prisma-schema-transformer ./schema.prisma

Instead of saving the result to the filesystem, you can also print it
  $ prisma-schema-transformer ./schema.prisma --print

Exclude some models from the output
  $ prisma-schema-transformer ./schema.prisma --deny knex_migrations --deny knex_migration_lock

Options:
  --print   Do not save
  --deny    Exlucde model from output
  --help    Help
  --version Version info

Motivation

Using snake_case in database and automatically transform generated Prisma schema to camelCase with @map and @@map as needed to map the new name back to the database.

There is a snippet provided by @TLadd, but I found regex a bit unreliable.

How does it work

getDMMF parses the Prisma schema file into dmmf(datamodel meta format), which we can use to do some post-processing on the Prisma internal data structure.

Deserializer

There does not seem to be a printer or a deserializer for DMMF, source. You can learn more about the implementation at deserializer.ts. It is responsible for converting a serialized Prisma schema, DMMF, back to plain text file.

It's hacky, but it works. Some test fixtures are taken from the @prisma/sdk repository for testing. We use the getDMMF method to compare the serialized structure of original and transformed Prisma schema, make sure they are identical.

Transformer

Manipulate the naming of Model and Field to follow the camelCase naming convention.

  • Model name is always singular.
  • Field name is singular by default with the execption of many-to-many relation.

License

This project is MIT licensed.