1.5.1 • Published 5 months ago

prisma-models-graph v1.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Prisma Models Graph Generator

This generator was bootstraped using create-prisma-generator

Generates a bi-directional models graph for schema without strict relationship defined in the schema, works via a custom schema annotation.

Getting Stared

1. Install npm:

npm install prisma-models-graph

2. Add the generator to the schema

generator modelsGraph {
  provider = "prisma-models-graph"
}

Additional options

generator modelsGraph {
  provider = "prisma-models-graph"
  exportJSON = true // Will also export a JSON models graph along with the typesafe models
}

Usage

  • Add custom relation annotation next to the field you want annotate relationship.
  • Format: /// [[<Relation Model>.<Relation Model Attribute>]] (The triple slash is important.)

    userId Int @map("user_id) /// [[User.id]]
  • With the above annotation, the generated models graph will be like this:

    {
      "users": {
        "attributes": [
          "id",
          "email",
          "name",
          "user_type_id"
        ],
        "relations": [
          {
            "modelName": "posts",
            "condition": "users.id = posts.user_id"
          }
        ]
      },
      "posts": {
        "attributes": [
          "id",
          "subject",
          "body",
          "user_id"
        ],
        "relations": [
          {
            "modelName": "users",
            "condition": "posts.user_id = users.id"
          }
        ]
      }
    }
  • To access the generated models graph, import it from @generated/models-graph. The generated models graph will be a typesafe object matching the models declared in schema.prisma.

    import { ModelsGraph } from '@generated/models-graph'
  • There are a few helper types available:

    import {
      ModelsGraph, // Generated models graph object
      ParsedModel, // Type definition of a singular generated model graph
      ParsedModels, // Type definition of all generated models graph
      ParsedModelRelation, // Type definition of the relation between two models
      ModelNames, // List of all generated models name,
      ParsedModelAttribute, // Type definition of generated models attribute
    } from '@generated/models-graph'
1.5.1

5 months ago

1.5.0

5 months ago

1.4.0

6 months ago

1.3.0

6 months ago

1.2.1

6 months ago

1.2.0

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago