1.5.0 • Published 2 years ago
prisma-mapper v1.5.0
prisma-mapper
A CLI that adds @map and @@map based on a json
Features
- Adds
@mapand@@map - Keeps the
@db.attributes for fields - Adds the
@updatedAtfor fields with the nameupdated_atorupdatedAt - The prisma schema is formatted by the
@prisma/internalsafter generation - The cli does not modify the current schema and generates a new one with the information from the current one
.pmignoreCan be used to avoid adding the@map/@@mapfor specific fields when running themapcommand
Node Versions
| Version | Supported |
|---|---|
| <= 15.x | ❌ |
| ^16.10.0 | ✅ |
| 17.x | ❌ |
| 18.x | ✅ |
| 19.x | ✅ |
| 20.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 generateor for camelCase by default
yarn prisma db pull --force
&& yarn prisma-mapper map --camel
&& yarn prisma generateWith 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 generateThe json looks like the following:
- The hasMap is added by generate if the prisma model has already a
@@map - The name is to add
@@mapfor a model name - In the fields object is to add
@mapfor 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 mapOptions
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