æ¦è¦
ã¿ãªããããã«ã¡ã¯ããã«ã¹ã¿ãã¯ã¨ã³ã¸ãã¢ã®é«ç¬ @takasehiromichi ã§ãã
ä»åã¯ãæ°ãã«ERå³ãä½æããéã«ãMermaid.js ã®æ¸ãå¿å°ããè¦ãç®ãè¯ãããã ã£ãã®ã§ãVSCodeä¸ã§æ¸ããããã¬ãã¥ã¼ã§ããããã«ãã¦ããERå³ãæ¸ãã¦ã¿ãã®ã§ãè¨äºã«ãããã¨æãã¾ãã
Mermaid
å ¬å¼ãµã¤ã
mermaid-cli ã¤ã³ã¹ãã¼ã«
ä¾ã«ãã£ã¦ãHomebrewã§å ¥ãã¾ãããã
brew install mermaid-cli
VSCode æ¡å¼µæ©è½ã¤ã³ã¹ãã¼ã«
以ä¸2ã¤ã®æ©è½ã使ç¨ãã¦ãã¾ãã
ERå³ä½æ
sample.mmd
ã¿ãããªæãã§ãã¡ã¤ã«ãä½æãã¦ããã以ä¸ã®ããã«æ¸ãã¾ãã
erDiagram CUSTOMER ||--o{ ORDER : places ORDER ||--|{ LINE-ITEM : contains CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
å³ã¯ãªãã¯ãã¦ãMermaid:Preview diagram
ãã¯ãªãã¯ãã¾ãã
ãããªæãã§è¡¨ç¤ºããã¾ãã
å®éã«ã¯ã以ä¸ã®ãããªæãã§ä½¿ã£ã¦ãã¾ãã
erDiagram customer { int id PK string name string number string address } order { int id PK int customer_id FK "customer" string delivery_address } customer ||--o{ order : "" item { int id PK int order_id FK "order" string product_code int quantity float price_per_unit } order ||--|{ item : ""
ã¾ããPKãFKãæ¸ããã¨ã§ãããããã®ã«ã©ã ã®å½¹å²ãæ確ã«ç¤ºãã¾ãã
FKã®æ¨ªã«ã¯å¤é¨ãã¼ã®å ãæ¸ãã¦ãã¾ããå¤é¨ãã¼åããã¡ãã¨å¤é¨ãã¼å ã®ãã¼ãã«åãå«ãããã«å½åããã¦ããã°ããã®ã§ãããããã§ãªããã¼ãã«ããã£ããããã¨å°ãã®ã§ãã³ã¡ã³ãã§å ¥ãã¦ãã¾ãã
ãã¨ã¯ããªã¬ã¼ã·ã§ã³ãå®ç¾©ããéã«ãä¸ãããã®ã¾ã¾æã£ã¦ããã°ããã ããªã®ã§ã便å©ã¨ããç¹ãããã¾ãã
ç»åã®çæ
å³ã¯ãªãã¯ãã¦ãMermaid:Generate image
ãã¯ãªãã¯ããã¨ãç»åãçæã§ãã¾ãã
ç»ååºåå½¢å¼ã¯ããããå¤æ´ãã¦ãã ããã
çæããå³
ã¾ã¨ã
ãã¯ãMermaidãªã©ã§èªåçæããæ¹ããä¾ãã°mysqlworkbenchãªã©ã§æä½æ¥ã§å³ã®ä½ç½®ãªã©ã調æ´ããããã¯é¥ãã«å©ä¾¿æ§ãé«ããªã¨æãã¾ãããä»å¾ãMermaidãæ´»ç¨ãã¦ããããã¨æãã¾ãã