Skip to content

Commit

Permalink
Merge pull request #12 from samchon/features/examples
Browse files Browse the repository at this point in the history
New tag `@minItems 1`
  • Loading branch information
samchon authored Nov 8, 2023
2 parents 0294bd6 + 9d43683 commit 3e34756
Show file tree
Hide file tree
Showing 9 changed files with 1,830 additions and 69 deletions.
96 changes: 48 additions & 48 deletions ERD.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ erDiagram
Int sequence
}
"bbs_article_snapshots" }|--|| "bbs_articles" : article
"bbs_article_snapshot_files" }|--|| "bbs_article_snapshots" : snapshot
"bbs_article_snapshot_files" }|--|| "attachment_files" : file
"bbs_article_comments" }|--|| "bbs_articles" : article
"bbs_article_snapshot_files" }o--|| "bbs_article_snapshots" : snapshot
"bbs_article_snapshot_files" }o--|| "attachment_files" : file
"bbs_article_comments" }o--|| "bbs_articles" : article
"bbs_article_comments" }o--o| "bbs_article_comments" : parent
"bbs_article_comment_snapshots" }|--|| "bbs_article_comments" : comment
"bbs_article_comment_snapshot_files" }|--|| "bbs_article_comment_snapshots" : snapshot
"bbs_article_comment_snapshot_files" }|--|| "attachment_files" : file
"bbs_article_comment_snapshot_files" }o--|| "bbs_article_comment_snapshots" : snapshot
"bbs_article_comment_snapshot_files" }o--|| "attachment_files" : file
```

### `attachment_files`
Expand Down Expand Up @@ -284,14 +284,14 @@ erDiagram
String shopping_sale_snapshot_channel_id FK
String shopping_channel_category_id FK
}
"shopping_channel_categories" }|--|| "shopping_channels" : channel
"shopping_channel_categories" }o--|| "shopping_channels" : channel
"shopping_channel_categories" }o--o| "shopping_channel_categories" : parent
"shopping_sales" }|--|| "shopping_sections" : section
"shopping_sales" }o--|| "shopping_sections" : section
"shopping_sale_snapshots" }|--|| "shopping_sales" : sale
"shopping_sale_snapshot_channels" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_channels" }|--|| "shopping_channels" : channel
"shopping_sale_snapshot_channel_categories" }|--|| "shopping_sale_snapshot_channels" : to_channel
"shopping_sale_snapshot_channel_categories" }|--|| "shopping_channel_categories" : category
"shopping_sale_snapshot_channels" }o--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_channels" }o--|| "shopping_channels" : channel
"shopping_sale_snapshot_channel_categories" }o--|| "shopping_sale_snapshot_channels" : to_channel
"shopping_sale_snapshot_channel_categories" }o--|| "shopping_channel_categories" : category
```

### `shopping_channels`
Expand Down Expand Up @@ -460,7 +460,7 @@ erDiagram
"shopping_customers" }o--|| "shopping_external_users" : external_user
"shopping_customers" }o--|| "shopping_citizens" : citizen
"shopping_members" }o--|| "shopping_citizens" : citizen
"shopping_member_emails" }|--|| "shopping_members" : member
"shopping_member_emails" }o--|| "shopping_members" : member
"shopping_sellers" |o--|| "shopping_members" : member
"shopping_administrators" |o--|| "shopping_members" : member
```
Expand Down Expand Up @@ -807,19 +807,19 @@ erDiagram
DateTime updated_at
DateTime deleted_at "nullable"
}
"shopping_sales" }|--|| "shopping_sections" : section
"shopping_sales" }o--|| "shopping_sections" : section
"shopping_sale_snapshots" }|--|| "shopping_sales" : sale
"shopping_sale_snapshot_channels" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_channels" }|--|| "shopping_channels" : channel
"shopping_sale_snapshot_channel_categories" }|--|| "shopping_sale_snapshot_channels" : to_channel
"shopping_sale_snapshot_channel_categories" }|--|| "shopping_channel_categories" : category
"shopping_sale_snapshot_channels" }o--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_channels" }o--|| "shopping_channels" : channel
"shopping_sale_snapshot_channel_categories" }o--|| "shopping_sale_snapshot_channels" : to_channel
"shopping_sale_snapshot_channel_categories" }o--|| "shopping_channel_categories" : category
"shopping_sale_snapshot_units" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_unit_options" }|--|| "shopping_sale_snapshot_units" : unit
"shopping_sale_snapshot_unit_option_candidates" }|--|| "shopping_sale_snapshot_unit_options" : option
"shopping_sale_snapshot_unit_options" }o--|| "shopping_sale_snapshot_units" : unit
"shopping_sale_snapshot_unit_option_candidates" }o--|| "shopping_sale_snapshot_unit_options" : option
"shopping_sale_snapshot_unit_stocks" }|--|| "shopping_sale_snapshot_units" : unit
"shopping_sale_snapshot_unit_stock_choices" }|--|| "shopping_sale_snapshot_unit_stocks" : stock
"shopping_sale_snapshot_unit_stock_choices" }|--|| "shopping_sale_snapshot_unit_option_candidates" : candidate
"shopping_channel_categories" }|--|| "shopping_channels" : channel
"shopping_sale_snapshot_unit_stock_choices" }o--|| "shopping_sale_snapshot_unit_stocks" : stock
"shopping_sale_snapshot_unit_stock_choices" }o--|| "shopping_sale_snapshot_unit_option_candidates" : candidate
"shopping_channel_categories" }o--|| "shopping_channels" : channel
"shopping_channel_categories" }o--o| "shopping_channel_categories" : parent
```

Expand Down Expand Up @@ -1256,17 +1256,17 @@ erDiagram
Int quantity
Int sequence
}
"shopping_cart_commodities" }|--|| "shopping_carts" : cart
"shopping_cart_commodities" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_cart_commodities" }o--|| "shopping_carts" : cart
"shopping_cart_commodities" }o--|| "shopping_sale_snapshots" : snapshot
"shopping_cart_commodity_stocks" }|--|| "shopping_cart_commodities" : commodity
"shopping_cart_commodity_stocks" }|--|| "shopping_sale_snapshot_units" : unit
"shopping_cart_commodity_stocks" }|--|| "shopping_sale_snapshot_unit_stocks" : stock
"shopping_cart_commodity_stock_choices" }|--|| "shopping_cart_commodity_stocks" : stock
"shopping_cart_commodity_stock_choices" }|--|| "shopping_sale_snapshot_unit_options" : option
"shopping_cart_commodity_stocks" }o--|| "shopping_sale_snapshot_units" : unit
"shopping_cart_commodity_stocks" }o--|| "shopping_sale_snapshot_unit_stocks" : stock
"shopping_cart_commodity_stock_choices" }o--|| "shopping_cart_commodity_stocks" : stock
"shopping_cart_commodity_stock_choices" }o--|| "shopping_sale_snapshot_unit_options" : option
"shopping_cart_commodity_stock_choices" }o--|| "shopping_sale_snapshot_unit_option_candidates" : candidate
"shopping_sale_snapshot_units" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_unit_options" }|--|| "shopping_sale_snapshot_units" : unit
"shopping_sale_snapshot_unit_option_candidates" }|--|| "shopping_sale_snapshot_unit_options" : option
"shopping_sale_snapshot_unit_options" }o--|| "shopping_sale_snapshot_units" : unit
"shopping_sale_snapshot_unit_option_candidates" }o--|| "shopping_sale_snapshot_unit_options" : option
"shopping_sale_snapshot_unit_stocks" }|--|| "shopping_sale_snapshot_units" : unit
```

Expand Down Expand Up @@ -1482,12 +1482,12 @@ erDiagram
}
"shopping_orders" }o--|| "shopping_addresses" : address
"shopping_order_goods" }|--|| "shopping_orders" : order
"shopping_order_goods" }|--|| "shopping_cart_commodities" : commodity
"shopping_order_goods" }o--|| "shopping_cart_commodities" : commodity
"shopping_order_publishes" |o--|| "shopping_orders" : order
"shopping_delivery_pieces" }|--|| "shopping_deliveries" : delivery
"shopping_delivery_pieces" }|--|| "shopping_order_goods" : good
"shopping_delivery_pieces" }|--|| "shopping_cart_commodity_stocks" : cart_commodity_stock
"shopping_delivery_journeys" }|--|| "shopping_deliveries" : delivery
"shopping_delivery_pieces" }o--|| "shopping_order_goods" : good
"shopping_delivery_pieces" }o--|| "shopping_cart_commodity_stocks" : cart_commodity_stock
"shopping_delivery_journeys" }o--|| "shopping_deliveries" : delivery
"shopping_cart_commodity_stocks" }|--|| "shopping_cart_commodities" : commodity
```

Expand Down Expand Up @@ -1773,16 +1773,16 @@ erDiagram
DateTime created_at
DateTime expired_at "nullable"
}
"shopping_coupon_criterias" }|--|| "shopping_coupons" : coupon
"shopping_coupon_criterias" }o--|| "shopping_coupons" : coupon
"shopping_coupon_section_criterias" |o--|| "shopping_coupon_criterias" : base
"shopping_coupon_channel_criterias" |o--|| "shopping_coupon_criterias" : base
"shopping_coupon_seller_criterias" |o--|| "shopping_coupon_criterias" : base
"shopping_coupon_sale_criterias" |o--|| "shopping_coupon_criterias" : base
"shopping_coupon_funnel_criterias" |o--|| "shopping_coupon_criterias" : base
"shopping_coupon_tickets" }|--|| "shopping_coupons" : coupon
"shopping_coupon_tickets" }o--|| "shopping_coupons" : coupon
"shopping_coupon_tickets" |o--|| "shopping_coupon_disposables" : disposable
"shopping_coupon_ticket_payments" |o--|| "shopping_coupon_tickets" : ticket
"shopping_coupon_disposables" }|--|| "shopping_coupons" : coupon
"shopping_coupon_disposables" }o--|| "shopping_coupons" : coupon
```

### `shopping_coupons`
Expand Down Expand Up @@ -2192,12 +2192,12 @@ erDiagram
DateTime created_at
DateTime deleted_at "nullable"
}
"shopping_deposit_histories" }|--|| "shopping_deposits" : deposit
"shopping_deposit_histories" }|--|| "shopping_citizens" : citizen
"shopping_deposit_charges" }|--|| "shopping_customers" : customer
"shopping_deposit_histories" }o--|| "shopping_deposits" : deposit
"shopping_deposit_histories" }o--|| "shopping_citizens" : citizen
"shopping_deposit_charges" }o--|| "shopping_customers" : customer
"shopping_deposit_charge_publishes" |o--|| "shopping_deposit_charges" : charge
"shopping_mileage_histories" }|--|| "shopping_mileages" : mileage
"shopping_mileage_histories" }|--|| "shopping_citizens" : citizen
"shopping_mileage_histories" }o--|| "shopping_mileages" : mileage
"shopping_mileage_histories" }o--|| "shopping_citizens" : citizen
"shopping_customers" }o--|| "shopping_citizens" : citizen
```

Expand Down Expand Up @@ -2421,16 +2421,16 @@ erDiagram
String shopping_sale_id FK
DateTime created_at
}
"shopping_sale_snapshot_inquiries" ||--|| "bbs_articles" : base
"shopping_sale_snapshot_inquiries" }|--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_inquiries" |o--|| "bbs_articles" : base
"shopping_sale_snapshot_inquiries" }o--|| "shopping_sale_snapshots" : snapshot
"shopping_sale_snapshot_questions" |o--|| "shopping_sale_snapshot_inquiries" : base
"shopping_sale_snapshot_reviews" |o--|| "shopping_sale_snapshot_inquiries" : base
"shopping_sale_snapshot_review_snapshots" ||--|| "bbs_article_snapshots" : base
"shopping_sale_snapshot_inquiry_answers" ||--|| "bbs_articles" : base
"shopping_sale_snapshot_review_snapshots" |o--|| "bbs_article_snapshots" : base
"shopping_sale_snapshot_inquiry_answers" |o--|| "bbs_articles" : base
"shopping_sale_snapshot_inquiry_answers" |o--|| "shopping_sale_snapshot_inquiries" : inquiry
"shopping_sale_snapshot_inquiry_comments" ||--|| "bbs_article_comments" : base
"shopping_sale_snapshot_inquiry_comments" |o--|| "bbs_article_comments" : base
"bbs_article_snapshots" }|--|| "bbs_articles" : article
"bbs_article_comments" }|--|| "bbs_articles" : article
"bbs_article_comments" }o--|| "bbs_articles" : article
"bbs_article_comments" }o--o| "bbs_article_comments" : parent
```

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Also, if you use `@erd <name>` instead of `@namespace <name>`, target model woul
- `@erd <name>`: Only ERD
- `@describe <name>`: Only markdown content
- `@hidden`: Neither ERD nor markdown content
- `@minItems 1`: Mandatory relationship when 1: **N** (`||---|{`)

```prisma
/// Both description and ERD on Actors chatper.
Expand All @@ -67,7 +68,14 @@ Also, if you use `@erd <name>` instead of `@namespace <name>`, target model woul
/// @namespace Actors
/// @erd Articles
/// @erd Orders
model shopping_customers {}
model shopping_customers {
/// The tag "minItems 1" means mandatory relationship `||---|{`.
///
/// Otherwise, no tag means optional relationship `||---o{`.
///
/// @minItems 1
login_histories shopping_customer_login_histories[]
}
/// Only description on Actors chapter.
///
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prisma-markdown",
"version": "1.0.6",
"version": "1.0.7",
"description": "Prisma Markdown documents generator including ERD diagrams and comment descriptions",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
28 changes: 20 additions & 8 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ model shopping_sellers {
deleted_at DateTime? @db.Timestamptz
//----
// RELATIONSHIPS
// RELATIONS
//----
member shopping_members @relation(fields: [shopping_member_id], references: [id], onDelete: Cascade)
shopping_order_goods shopping_order_goods[]
Expand Down Expand Up @@ -1223,9 +1223,11 @@ model shopping_sales {
//----
// RELATIONS
//----
section shopping_sections @relation(fields: [shopping_section_id], references: [id], onDelete: Cascade)
sellerCustomer shopping_customers @relation(fields: [shopping_seller_customer_id], references: [id], onDelete: Cascade)
snapshots shopping_sale_snapshots[]
section shopping_sections @relation(fields: [shopping_section_id], references: [id], onDelete: Cascade)
sellerCustomer shopping_customers @relation(fields: [shopping_seller_customer_id], references: [id], onDelete: Cascade)
/// @minItems 1
snapshots shopping_sale_snapshots[]
inquiries shopping_sale_snapshot_inquiries[]
shopping_coupon_sale_criterias shopping_coupon_sale_criterias[]
Expand Down Expand Up @@ -1280,8 +1282,10 @@ model shopping_sale_snapshots {
content shopping_sale_snapshot_contents?
to_channels shopping_sale_snapshot_channels[]
units shopping_sale_snapshot_units[]
tags shopping_sale_snapshot_tags[]
/// @minItems 1
units shopping_sale_snapshot_units[]
tags shopping_sale_snapshot_tags[]
shopping_cart_commodities shopping_cart_commodities[]
shopping_sale_snapshot_inquiries shopping_sale_snapshot_inquiries[]
Expand Down Expand Up @@ -1542,6 +1546,8 @@ model shopping_sale_snapshot_units {
options shopping_sale_snapshot_unit_options[]
/// List of stocks.
///
/// @minItems 1
stocks shopping_sale_snapshot_unit_stocks[]
shopping_cart_commodity_stocks shopping_cart_commodity_stocks[]
Expand Down Expand Up @@ -2008,6 +2014,8 @@ model shopping_cart_commodities {
snapshot shopping_sale_snapshots @relation(fields: [shopping_sale_snapshot_id], references: [id], onDelete: Cascade)
/// List of wrapper of final stocks.
///
/// @minItems 1
stocks shopping_cart_commodity_stocks[]
/// List of order goods for purchase.
Expand Down Expand Up @@ -2249,6 +2257,8 @@ model shopping_orders {
publish shopping_order_publishes?
/// List of goods to purchase.
///
/// @minItems 1
goods shopping_order_goods[]
/// List of payed tickets for discount
Expand Down Expand Up @@ -2471,10 +2481,12 @@ model shopping_deliveries {
//----
sellerCustomer shopping_customers @relation(fields: [shopping_seller_customer_id], references: [id], onDelete: Cascade)
journeys shopping_delivery_journeys[]
pieces shopping_delivery_pieces[]
/// @minItems 1
pieces shopping_delivery_pieces[]
// Considering principles, it must be UK.
// However, some seller takes a mistake, so it can't be.
@@index([shopping_seller_customer_id, created_at])
@@index([invoice_code])
@@index([created_at])
Expand Down
24 changes: 23 additions & 1 deletion src/writers/MermaidWriter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DMMF } from "@prisma/generator-helper";
import { PrismaUtil } from "../utils/PrismaUtil";

export namespace MermaidWriter {
export const write = (chapter: DMMF.Model[]) =>
Expand Down Expand Up @@ -80,7 +81,9 @@ export namespace MermaidWriter {
),
))
? "o"
: "|",
: isMandatoryMany({ model: props.model, field, target })
? "|"
: "o",
"--",
props.model === target ? "o" : "|",
"|",
Expand All @@ -93,4 +96,23 @@ export namespace MermaidWriter {
field.name,
].join(" ");
};

const isMandatoryMany = (props: {
target: DMMF.Model;
model: DMMF.Model;
field: DMMF.Field;
}): boolean => {
const opposite = props.target.fields.find(
(f) =>
f.relationName === props.field.relationName &&
f.type === props.model.name,
);
if (opposite === undefined) return false;

const values: string[] = PrismaUtil.tagValues("minItems")(opposite);
if (values.length === 0) return false;

const numeric: number = Number(values[0]);
return !isNaN(numeric) && numeric >= 1;
};
}
Loading

0 comments on commit 3e34756

Please sign in to comment.