Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: to release new version #12

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,56 @@ generator jsonSchema {
## Usage

- Add custom relation annotation next to the field you want annotate relationship.
- Format: `/// [[<Relation Model>.<Relation Model Attribute>]]`
<img src='./assets/annotation.png'>

- Format: `/// [[<Relation Model>.<Relation Model Attribute>]]` ( <b>The triple slash is important</b> )
- With the above annotation, the generated models graph will be like this:
<img src='./assets/output.png'>

```js
{
"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`.

```js
import { ModelsGraph } from '@generated/models-graph'
```

- There are a few helper types available:

```js
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
} from '@generated/models-graph'
```
Binary file removed assets/annotation.png
Binary file not shown.
Binary file removed assets/output.png
Binary file not shown.
Loading