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

@raresail/prisma-mapper

v1.7.0

Published

A CLI that adds @Map, @@Map, @updatedAt based on a json or camel case for the prisma schema

Downloads

258

Readme

@raresail/prisma-mapper

Web Documentation

CodeQL Node.js CI Yarn Audit CI NPM Package Downloads


A CLI that adds @map and @@map based on a json

Installation

NPM

npm install -g @raresail/prisma-mapper

Yarn

yarn global add @raresail/prisma-mapper

Features

  • Adds @map and @@map
  • Keeps the @db. attributes for fields
  • Adds the @updatedAt for fields with the name updated_at or updatedAt
  • The prisma schema is formatted by the @prisma/internals after generation
  • The cli does not modify the current schema and generates a new one with the information from the current one
  • .pmignore Can be used to avoid adding the @map/@@map for specific fields when running the map command

Node Versions

| Version | Supported | | ------- | --------- | | <= 19.x | ❌ | | 20.x | ✅ | | 21.x | ❌ | | >= 22.x | ✅ |

Getting Started

If the prisma schema is often pulled you can use the cli like

yarn prisma db pull --force
  && yarn prisma-mapper generate
  && yarn prisma-mapper map
  && yarn prisma generate

or for camelCase by default

yarn prisma db pull --force
  && yarn prisma-mapper map --camel
  && yarn prisma generate

With db pull force you get the latest schema updates and force overwrites the file.

The generate command creates a json called prisma-mapper.json in the root, if the json already exists it adds in it any new fields/models. (NOT FOR --camel option)

yarn prisma-mapper generate

The json looks like the following:

  • The hasMap is added by generate if the prisma model has already a @@map
  • The name is to add @@map for a model name
  • In the fields object is to add @map for each field
{
  "model": {
    "hasMap": false,
    "name": null,
    "fields": {
      "field_name_1": null,
      "field_name_2": null
    }
  }
}

The map command modifies the schema.prisma file and adds the @map and @@map for each field and model, if the field/model-name is in the json file, the field/model will be renamed to the new name.

yarn prisma-mapper map

Options

Both 2 commands have an option --schema "new schema path to use the schema from a different location

For both commands

  • --schema "new schema path
    • is to use the schema from a different location
  • --camel
    • for map it does the mapping without a json file
    • for generate it defaults the namings to camel case in the generated json

Map options

  • -o --output "output schema path"
    • after mapping save the schema to another location

Ignore File

Example for the .pmignore file

enum_ignore_s_contents.someValue
enum_ignore_contents.*
enum_ignore_model

model_ignore_s_contents.updated_at
model_ignore_s_contents.created_at
model_ignore_s_contents.enum_three
model_ignore_contents.*
model_ignore