mikro-orm-markdown 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.ko.md +194 -0
- package/README.md +194 -0
- package/dist/cli.cjs +534 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +511 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +489 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +54 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +461 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0-alpha.1] - 2026-06-11
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- CLI (`mikro-orm-markdown`) with `--config`, `--out`, `--title`, `--src` options
|
|
13
|
+
- Programmatic API: `generateMarkdown(options)`
|
|
14
|
+
- Mermaid `erDiagram` generation from MikroORM entity metadata
|
|
15
|
+
- MikroORM-specific concept visualization:
|
|
16
|
+
- `@Embedded` value object columns (flat columns with type annotation)
|
|
17
|
+
- Single Table Inheritance (STI) with discriminator column and hierarchy arrows
|
|
18
|
+
- `@Formula` computed columns (SQL expression shown in Key column)
|
|
19
|
+
- Actual DB column names derived from NamingStrategy
|
|
20
|
+
- Index and constraint documentation
|
|
21
|
+
- JSDoc tag-based namespace grouping (`@namespace`, `@erd`, `@describe`, `@hidden`)
|
|
22
|
+
- Per-entity column tables with type, key, and description
|
|
23
|
+
- ESM + CJS dual package output
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# mikro-orm-markdown
|
|
2
|
+
|
|
3
|
+
[MikroORM](https://mikro-orm.io) 엔티티에서 **Mermaid ERD + Markdown 문서**를 자동으로 생성합니다.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/mikro-orm-markdown)
|
|
6
|
+
[](https://github.com/iamkanguk97/mikro-orm-markdown/actions)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
[English](./README.md)
|
|
10
|
+
|
|
11
|
+
> [@samchon](https://github.com/samchon)의 [prisma-markdown](https://github.com/samchon/prisma-markdown)에서 큰 영감을 받았습니다. 좋은 아이디어에 감사드립니다.
|
|
12
|
+
|
|
13
|
+
MikroORM에서도 동일한 ERD + Markdown 경험을 제공하며, Prisma로는 표현할 수 없는 MikroORM 고유 개념도 함께 시각화합니다.
|
|
14
|
+
|
|
15
|
+
- **Embeddable** — 별도 테이블 없이 소유 엔티티의 테이블 안에 컬럼을 펼쳐서 저장하는 값 객체입니다. 예를 들어 `Address` 값 객체는 `address_street`, `address_city` 등의 컬럼으로 저장됩니다. DDD의 Value Object와 같은 개념입니다.
|
|
16
|
+
- **Single Table Inheritance (STI)** — `Dog`, `Cat` 같은 자식 클래스가 `animals` 테이블 하나를 공유합니다. `type` 같은 discriminator 컬럼으로 어떤 자식 클래스인지 구분합니다.
|
|
17
|
+
- **@Formula** — 실제 DB 컬럼 없이 SELECT 시 SQL 식으로 값을 계산하는 가상 컬럼입니다. 예를 들어 `LENGTH(name)`은 DB에 컬럼이 없지만 조회 시 이름의 길이를 반환합니다.
|
|
18
|
+
- NamingStrategy가 적용된 **실제 DB 컬럼명**
|
|
19
|
+
- **인덱스 및 제약 조건**
|
|
20
|
+
|
|
21
|
+
DB에 연결하지 않으므로 MikroORM이 지원하는 모든 DB(PostgreSQL, MySQL, SQLite, MSSQL 등)에서 동작합니다.
|
|
22
|
+
|
|
23
|
+
## 요구사항
|
|
24
|
+
|
|
25
|
+
- Node.js >= 18
|
|
26
|
+
- `@mikro-orm/core` >= 6 (peer dependency)
|
|
27
|
+
- TypeScript 설정 파일 사용 시 `tsx` 또는 `ts-node` 필요
|
|
28
|
+
|
|
29
|
+
## 설치
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -D mikro-orm-markdown
|
|
33
|
+
# 또는
|
|
34
|
+
pnpm add -D mikro-orm-markdown
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 빠른 시작
|
|
38
|
+
|
|
39
|
+
`package.json`에 스크립트를 한 번 등록합니다:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"scripts": {
|
|
44
|
+
"erd": "mikro-orm-markdown --config ./mikro-orm.config.js --out ./ERD.md --title 'My Database' --src 'src/entities/**/*.ts'"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
TypeScript 설정 파일을 사용한다면 `tsx`를 앞에 붙입니다:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"scripts": {
|
|
54
|
+
"erd": "tsx ./node_modules/.bin/mikro-orm-markdown --config ./mikro-orm.config.ts --out ./ERD.md --title 'My Database' --src 'src/entities/**/*.ts'"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
이후에는 아래 명령어 하나로 실행합니다:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm run erd
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI 옵션
|
|
66
|
+
|
|
67
|
+
| 옵션 | 기본값 | 설명 |
|
|
68
|
+
|------|--------|------|
|
|
69
|
+
| `-c, --config <path>` | *(필수)* | MikroORM 설정 파일 경로 |
|
|
70
|
+
| `-o, --out <path>` | `./ERD.md` | 출력 Markdown 파일 경로 |
|
|
71
|
+
| `-t, --title <string>` | `Database Schema` | 문서 H1 제목 |
|
|
72
|
+
| `-s, --src <glob>` | — | 엔티티 소스 파일 glob 패턴 (반복 가능). JSDoc 태그 추출에 사용됩니다. |
|
|
73
|
+
|
|
74
|
+
## JSDoc 태그
|
|
75
|
+
|
|
76
|
+
엔티티 클래스에 JSDoc 태그를 추가해 문서의 섹션과 노출 여부를 제어합니다.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
/**
|
|
80
|
+
* 등록된 사용자가 작성한 블로그 게시글입니다.
|
|
81
|
+
* @namespace Blog
|
|
82
|
+
*/
|
|
83
|
+
@Entity()
|
|
84
|
+
export class Post {
|
|
85
|
+
/** 게시글 제목 */
|
|
86
|
+
@Property()
|
|
87
|
+
title!: string;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| 태그 | 설명 |
|
|
92
|
+
|------|------|
|
|
93
|
+
| `@namespace <Name>` | `Name` 섹션에 포함 (ERD + 본문 표) |
|
|
94
|
+
| `@erd <Name>` | `Name` 섹션의 ERD 다이어그램에만 포함 |
|
|
95
|
+
| `@describe <Name>` | `Name` 섹션의 본문 표에만 포함 |
|
|
96
|
+
| `@hidden` | 문서 전체에서 제외 |
|
|
97
|
+
|
|
98
|
+
태그가 없는 엔티티는 `default` 섹션에 들어갑니다.
|
|
99
|
+
하나의 엔티티에 여러 태그를 지정할 수 있습니다.
|
|
100
|
+
|
|
101
|
+
> **NestJS Swagger Plugin**: `@namespace`, `@erd`, `@describe`, `@hidden`은 Swagger가 인식하지 못하는 커스텀 태그이므로 무시됩니다. 엔티티 클래스를 DTO로 직접 사용하는 구조라면 JSDoc 설명이 Swagger 문서에도 함께 표시될 수 있지만, 기능적인 충돌은 없습니다.
|
|
102
|
+
|
|
103
|
+
## 출력 예시
|
|
104
|
+
|
|
105
|
+
네임스페이스마다 섹션이 생성되고, 각 섹션에는 Mermaid ERD 블록과 엔티티별 컬럼 표가 포함됩니다.
|
|
106
|
+
|
|
107
|
+
````markdown
|
|
108
|
+
## Blog
|
|
109
|
+
|
|
110
|
+
```mermaid
|
|
111
|
+
erDiagram
|
|
112
|
+
Post {
|
|
113
|
+
integer id PK
|
|
114
|
+
string title
|
|
115
|
+
text body
|
|
116
|
+
integer author_id FK "author"
|
|
117
|
+
}
|
|
118
|
+
Author {
|
|
119
|
+
integer id PK
|
|
120
|
+
string name
|
|
121
|
+
string email UK
|
|
122
|
+
}
|
|
123
|
+
Post }o--|| Author : "author"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Post
|
|
127
|
+
|
|
128
|
+
> 등록된 사용자가 작성한 블로그 게시글입니다.
|
|
129
|
+
|
|
130
|
+
| Column | Type | Key | Nullable | Description |
|
|
131
|
+
|--------|------|-----|----------|-------------|
|
|
132
|
+
| id | integer | PK | | |
|
|
133
|
+
| title | string | | | 게시글 제목 |
|
|
134
|
+
| body | text | | Y | |
|
|
135
|
+
| author_id | integer | FK (author) | | |
|
|
136
|
+
````
|
|
137
|
+
|
|
138
|
+
**Key 컬럼 주석 의미:**
|
|
139
|
+
|
|
140
|
+
| 표기 | 의미 |
|
|
141
|
+
|------|------|
|
|
142
|
+
| `formula: <expr>` | `@Formula` 계산 컬럼 — 실제 DB 컬럼 없음 |
|
|
143
|
+
| `[EmbeddableType]` | `@Embedded` 값 객체에서 flat으로 저장된 컬럼 |
|
|
144
|
+
| `discriminator` | STI 구분자 컬럼 |
|
|
145
|
+
|
|
146
|
+
## 참고 사항
|
|
147
|
+
|
|
148
|
+
### Single Table Inheritance (STI)
|
|
149
|
+
|
|
150
|
+
STI는 여러 엔티티 클래스가 하나의 DB 테이블을 공유하는 패턴으로, discriminator 컬럼으로 행을 구분합니다.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
@Entity({ discriminatorColumn: 'type', abstract: true })
|
|
154
|
+
export class Animal {
|
|
155
|
+
@PrimaryKey()
|
|
156
|
+
id!: number;
|
|
157
|
+
|
|
158
|
+
@Property()
|
|
159
|
+
name!: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@Entity({ discriminatorValue: 'dog' })
|
|
163
|
+
export class Dog extends Animal {
|
|
164
|
+
@Property({ nullable: true })
|
|
165
|
+
breed?: string;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
엔티티에 `discriminatorColumn`이 설정되어 있으면 `mikro-orm-markdown`이 자동으로 감지해 출력에 discriminator 컬럼을 표시합니다.
|
|
170
|
+
|
|
171
|
+
> **대부분의 프로젝트에는 권장하지 않습니다.** STI는 테이블 단순화 대신 쿼리 복잡도 증가와 nullable 컬럼 낭비를 초래합니다. 여러 엔티티 타입을 하나의 테이블에 저장해야 하는 명확한 이유가 있을 때만 사용하세요.
|
|
172
|
+
|
|
173
|
+
## 고급 사용법
|
|
174
|
+
|
|
175
|
+
### 프로그래밍 API
|
|
176
|
+
|
|
177
|
+
커스텀 빌드 스크립트에 통합하거나 출력 결과를 직접 가공해야 할 때 사용합니다:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { generateMarkdown } from 'mikro-orm-markdown';
|
|
181
|
+
import ormConfig from './mikro-orm.config.js';
|
|
182
|
+
|
|
183
|
+
const markdown = await generateMarkdown({
|
|
184
|
+
orm: ormConfig,
|
|
185
|
+
title: 'My Database',
|
|
186
|
+
src: ['src/entities/**/*.ts'],
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await fs.writeFile('./ERD.md', markdown, 'utf-8');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## 라이선스
|
|
193
|
+
|
|
194
|
+
MIT
|
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# mikro-orm-markdown
|
|
2
|
+
|
|
3
|
+
Generate **Mermaid ERD + Markdown documentation** from your [MikroORM](https://mikro-orm.io) entities.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/mikro-orm-markdown)
|
|
6
|
+
[](https://github.com/iamkanguk97/mikro-orm-markdown/actions)
|
|
7
|
+
[](https://opensource.org/licenses/MIT)
|
|
8
|
+
|
|
9
|
+
[한국어 문서](./README.ko.md)
|
|
10
|
+
|
|
11
|
+
> Heavily inspired by [prisma-markdown](https://github.com/samchon/prisma-markdown) by [@samchon](https://github.com/samchon). Thank you for the great idea.
|
|
12
|
+
|
|
13
|
+
This tool brings the same ERD + Markdown experience to MikroORM, with additional visualization for MikroORM-specific concepts that cannot be expressed in Prisma:
|
|
14
|
+
|
|
15
|
+
- **Embeddable** — a value object whose fields are stored as flat columns inside the owning entity's table (e.g. `address_street`, `address_city`). No separate table is created.
|
|
16
|
+
- **Single Table Inheritance (STI)** — subclasses like `Dog` and `Cat` share one `animals` table. A discriminator column (e.g. `type`) distinguishes which subclass each row belongs to.
|
|
17
|
+
- **@Formula** — a virtual column with no physical DB column. Its value is computed by a SQL expression at SELECT time (e.g. `LENGTH(name)`).
|
|
18
|
+
- **Actual DB column names** derived from your NamingStrategy
|
|
19
|
+
- **Indexes and constraints**
|
|
20
|
+
|
|
21
|
+
Works with all databases supported by MikroORM (PostgreSQL, MySQL, SQLite, MSSQL, and more) — no database connection required.
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node.js >= 18
|
|
26
|
+
- `@mikro-orm/core` >= 6 (peer dependency)
|
|
27
|
+
- TypeScript config files require `tsx` or `ts-node`
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -D mikro-orm-markdown
|
|
33
|
+
# or
|
|
34
|
+
pnpm add -D mikro-orm-markdown
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
Add a script to your `package.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"scripts": {
|
|
44
|
+
"erd": "mikro-orm-markdown --config ./mikro-orm.config.js --out ./ERD.md --title 'My Database' --src 'src/entities/**/*.ts'"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For TypeScript config files, use `tsx`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"scripts": {
|
|
54
|
+
"erd": "tsx ./node_modules/.bin/mikro-orm-markdown --config ./mikro-orm.config.ts --out ./ERD.md --title 'My Database' --src 'src/entities/**/*.ts'"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then run:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm run erd
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI Options
|
|
66
|
+
|
|
67
|
+
| Option | Default | Description |
|
|
68
|
+
|--------|---------|-------------|
|
|
69
|
+
| `-c, --config <path>` | *(required)* | Path to MikroORM config file |
|
|
70
|
+
| `-o, --out <path>` | `./ERD.md` | Output Markdown file path |
|
|
71
|
+
| `-t, --title <string>` | `Database Schema` | H1 heading of the generated document |
|
|
72
|
+
| `-s, --src <glob>` | — | Glob pattern for entity source files (repeatable). Enables JSDoc tag extraction. |
|
|
73
|
+
|
|
74
|
+
## JSDoc Tags
|
|
75
|
+
|
|
76
|
+
Annotate your entity classes to control sections and visibility in the generated document.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
/**
|
|
80
|
+
* Blog post authored by a registered user.
|
|
81
|
+
* @namespace Blog
|
|
82
|
+
*/
|
|
83
|
+
@Entity()
|
|
84
|
+
export class Post {
|
|
85
|
+
/** Post title */
|
|
86
|
+
@Property()
|
|
87
|
+
title!: string;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Tag | Description |
|
|
92
|
+
|-----|-------------|
|
|
93
|
+
| `@namespace <Name>` | Include entity in section `Name` (ERD + text table) |
|
|
94
|
+
| `@erd <Name>` | Include in section `Name`'s ERD diagram only |
|
|
95
|
+
| `@describe <Name>` | Include in section `Name`'s text table only |
|
|
96
|
+
| `@hidden` | Exclude entity from the entire document |
|
|
97
|
+
|
|
98
|
+
Entities with no tag are placed in the `default` section.
|
|
99
|
+
An entity can carry multiple tags to appear in more than one section.
|
|
100
|
+
|
|
101
|
+
> **NestJS Swagger Plugin**: `@namespace`, `@erd`, `@describe`, and `@hidden` are custom tags that Swagger does not recognize and will ignore. If you use your entity classes directly as DTOs, the JSDoc description may appear in your Swagger docs as well — but there is no functional conflict.
|
|
102
|
+
|
|
103
|
+
## Output Example
|
|
104
|
+
|
|
105
|
+
Each namespace becomes a section with a Mermaid ERD block followed by per-entity column tables.
|
|
106
|
+
|
|
107
|
+
````markdown
|
|
108
|
+
## Blog
|
|
109
|
+
|
|
110
|
+
```mermaid
|
|
111
|
+
erDiagram
|
|
112
|
+
Post {
|
|
113
|
+
integer id PK
|
|
114
|
+
string title
|
|
115
|
+
text body
|
|
116
|
+
integer author_id FK "author"
|
|
117
|
+
}
|
|
118
|
+
Author {
|
|
119
|
+
integer id PK
|
|
120
|
+
string name
|
|
121
|
+
string email UK
|
|
122
|
+
}
|
|
123
|
+
Post }o--|| Author : "author"
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Post
|
|
127
|
+
|
|
128
|
+
> Blog post authored by a registered user.
|
|
129
|
+
|
|
130
|
+
| Column | Type | Key | Nullable | Description |
|
|
131
|
+
|--------|------|-----|----------|-------------|
|
|
132
|
+
| id | integer | PK | | |
|
|
133
|
+
| title | string | | | Post title |
|
|
134
|
+
| body | text | | Y | |
|
|
135
|
+
| author_id | integer | FK (author) | | |
|
|
136
|
+
````
|
|
137
|
+
|
|
138
|
+
MikroORM-specific annotations in the **Key** column:
|
|
139
|
+
|
|
140
|
+
| Annotation | Meaning |
|
|
141
|
+
|------------|---------|
|
|
142
|
+
| `formula: <expr>` | `@Formula` computed column — no physical DB column |
|
|
143
|
+
| `[EmbeddableType]` | Flat column inlined from an `@Embedded` value object |
|
|
144
|
+
| `discriminator` | STI discriminator column |
|
|
145
|
+
|
|
146
|
+
## Notes
|
|
147
|
+
|
|
148
|
+
### Single Table Inheritance (STI)
|
|
149
|
+
|
|
150
|
+
STI is a pattern where multiple entity classes share a single database table, using a discriminator column to tell rows apart.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
@Entity({ discriminatorColumn: 'type', abstract: true })
|
|
154
|
+
export class Animal {
|
|
155
|
+
@PrimaryKey()
|
|
156
|
+
id!: number;
|
|
157
|
+
|
|
158
|
+
@Property()
|
|
159
|
+
name!: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@Entity({ discriminatorValue: 'dog' })
|
|
163
|
+
export class Dog extends Animal {
|
|
164
|
+
@Property({ nullable: true })
|
|
165
|
+
breed?: string;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
When an entity uses `discriminatorColumn`, `mikro-orm-markdown` automatically detects it and marks the discriminator column in the output.
|
|
170
|
+
|
|
171
|
+
> **Not recommended for most projects.** STI trades table simplicity for query complexity and sparse nullable columns. Use it only when you have a clear reason to store multiple entity types in one table.
|
|
172
|
+
|
|
173
|
+
## Advanced Usage
|
|
174
|
+
|
|
175
|
+
### Programmatic API
|
|
176
|
+
|
|
177
|
+
If you need to integrate ERD generation into a custom build script or process the output programmatically:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { generateMarkdown } from 'mikro-orm-markdown';
|
|
181
|
+
import ormConfig from './mikro-orm.config.js';
|
|
182
|
+
|
|
183
|
+
const markdown = await generateMarkdown({
|
|
184
|
+
orm: ormConfig,
|
|
185
|
+
title: 'My Database',
|
|
186
|
+
src: ['src/entities/**/*.ts'],
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
await fs.writeFile('./ERD.md', markdown, 'utf-8');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|