Skip to content

Commit

Permalink
Merge pull request #16 from janpio/patch-1
Browse files Browse the repository at this point in the history
docs(README): indentation
  • Loading branch information
dangchinh25 authored Nov 13, 2023
2 parents 22888aa + 95fd988 commit 4f0f47e
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,60 @@ generator modelsGraph {
- Add custom relation annotation next to the field you want annotate relationship.
- Format: `/// [[<Relation Model>.<Relation Model Attribute>]]` (<b>The triple slash is important.</b>)

```prisma
userId Int @map("user_id) /// [[User.id]]
```
```prisma
userId Int @map("user_id) /// [[User.id]]
```

- With the above annotation, the generated models graph will be like this:

```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"
}
]
```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'
```
```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,
ParsedModelAttribute, // Type definition of generated models attribute
} from '@generated/models-graph'
```
```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,
ParsedModelAttribute, // Type definition of generated models attribute
} from '@generated/models-graph'
```

0 comments on commit 4f0f47e

Please sign in to comment.