@cuongph.dev/dbdocgen 0.1.0 → 0.1.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/README.md +97 -37
- package/dist/cli/index.cjs +1080 -163
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +1090 -172
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +1086 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1095 -206
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -10,11 +10,12 @@ The database schema is the **single source of truth**. All table names, column t
|
|
|
10
10
|
|
|
11
11
|
- Parse `schema.sql` (PostgreSQL, MySQL/MariaDB primary support)
|
|
12
12
|
- Export to 5 formats: Excel, Markdown, HTML, Mermaid, Word
|
|
13
|
-
-
|
|
14
|
-
-
|
|
13
|
+
- Excel workbook with **Overview** sheet (summary + hyperlinks), **ER Diagram** sheet, and one sheet per table
|
|
14
|
+
- **ER diagram** embedded in Excel/HTML/Markdown/Word (ELK layout PNG + Mermaid); HTML page with pan/zoom
|
|
15
|
+
- A5:SQL-style **10-column** definition tables (Size, Min, Max, Unique, Notes, …)
|
|
15
16
|
- HTML with **index page** and per-table detail pages (PK/FK highlighting)
|
|
16
17
|
- Localized output labels: English (`en`) and Japanese (`jp`)
|
|
17
|
-
-
|
|
18
|
+
- Configurable **output parent folder** (`outDir`); each run creates `{outDir}/db_doc_gen_{yymmddhhmm}`
|
|
18
19
|
- Step-by-step progress logging during generation
|
|
19
20
|
- Config file support via [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig)
|
|
20
21
|
- Programmatic API for integration into CI or custom tooling
|
|
@@ -46,7 +47,7 @@ dbdocgen init
|
|
|
46
47
|
dbdocgen generate
|
|
47
48
|
|
|
48
49
|
# Or pass options directly
|
|
49
|
-
dbdocgen generate --schema ./database/schema.sql --out ./
|
|
50
|
+
dbdocgen generate --schema ./database/schema.sql --out ./output
|
|
50
51
|
```
|
|
51
52
|
|
|
52
53
|
### Development (from source)
|
|
@@ -71,7 +72,7 @@ dbdocgen generate [options]
|
|
|
71
72
|
| Option | Description |
|
|
72
73
|
| ------ | ----------- |
|
|
73
74
|
| `--schema <path>` | Path to the SQL schema file (default: from config or `./schema.sql`) |
|
|
74
|
-
| `--out <path>` |
|
|
75
|
+
| `--out <path>` | Parent output directory (default: `./output`; each run creates `db_doc_gen_{yymmddhhmm}` inside) |
|
|
75
76
|
| `--format <list>` | Comma-separated formats: `excel`, `markdown`, `html`, `diagram`, `word` (default: all) |
|
|
76
77
|
| `--config <path>` | Config file path (default: auto-detected) |
|
|
77
78
|
|
|
@@ -81,6 +82,7 @@ dbdocgen generate [options]
|
|
|
81
82
|
[dbdocgen] Loading configuration...
|
|
82
83
|
[dbdocgen] Configuration loaded
|
|
83
84
|
schema: ./database/schema.sql
|
|
85
|
+
outputParent: ./output
|
|
84
86
|
outDir: ./output/db_doc_gen_2606281947
|
|
85
87
|
formats: excel, markdown, html, diagram, word
|
|
86
88
|
language: en
|
|
@@ -116,12 +118,23 @@ dbdocgen validate --schema ./database/schema.sql
|
|
|
116
118
|
|
|
117
119
|
### `clean`
|
|
118
120
|
|
|
119
|
-
Remove
|
|
121
|
+
Remove generated documentation folders.
|
|
120
122
|
|
|
121
123
|
```bash
|
|
122
|
-
|
|
124
|
+
# Remove all db_doc_gen_* run folders under the parent directory
|
|
125
|
+
dbdocgen clean --out ./output
|
|
126
|
+
|
|
127
|
+
# Remove one specific run
|
|
128
|
+
dbdocgen clean --out ./output/db_doc_gen_2606281947
|
|
123
129
|
```
|
|
124
130
|
|
|
131
|
+
| Target path | Behavior |
|
|
132
|
+
| ----------- | -------- |
|
|
133
|
+
| Parent dir (e.g. `./output`) | Deletes every `db_doc_gen_*` subdirectory inside |
|
|
134
|
+
| Run dir (e.g. `./output/db_doc_gen_2606281947`) | Deletes that folder only |
|
|
135
|
+
|
|
136
|
+
Uses `outDir` from config when `--out` is omitted (default parent: `./output`).
|
|
137
|
+
|
|
125
138
|
### `config show`
|
|
126
139
|
|
|
127
140
|
Print the resolved configuration (merges config file + CLI defaults).
|
|
@@ -164,6 +177,7 @@ CLI options override config file values.
|
|
|
164
177
|
```json
|
|
165
178
|
{
|
|
166
179
|
"schema": "./database/schema.sql",
|
|
180
|
+
"outDir": "./output",
|
|
167
181
|
"dialect": "mysql",
|
|
168
182
|
"output": {
|
|
169
183
|
"formats": ["excel", "markdown", "html", "diagram", "word"],
|
|
@@ -172,6 +186,12 @@ CLI options override config file values.
|
|
|
172
186
|
}
|
|
173
187
|
```
|
|
174
188
|
|
|
189
|
+
`outDir` is the **parent folder only**. The CLI always writes into a new timestamped subdirectory:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
{outDir}/db_doc_gen_{yymmddhhmm}/
|
|
193
|
+
```
|
|
194
|
+
|
|
175
195
|
### Config fields
|
|
176
196
|
|
|
177
197
|
| Field | Type | Default | Description |
|
|
@@ -180,8 +200,7 @@ CLI options override config file values.
|
|
|
180
200
|
| `dialect` | `string` | auto-detected | SQL dialect hint: `postgres`, `mysql`, `mariadb`, `sqlite`, `mssql` |
|
|
181
201
|
| `output.formats` | `string[]` | all formats | Which output formats to generate |
|
|
182
202
|
| `output.language` | `string` | `"en"` | Label language: `en` or `jp` |
|
|
183
|
-
|
|
184
|
-
> **Note:** `outDir` is not set in config. Each `generate` run uses `--out` if provided, otherwise a new timestamped directory under `./output/`.
|
|
203
|
+
| `outDir` | `string` | `"./output"` | Parent folder for generated runs (`{outDir}/db_doc_gen_{yymmddhhmm}`) |
|
|
185
204
|
|
|
186
205
|
## Output Structure
|
|
187
206
|
|
|
@@ -189,14 +208,17 @@ Each `generate` run writes to a dedicated directory:
|
|
|
189
208
|
|
|
190
209
|
```
|
|
191
210
|
output/db_doc_gen_2606281947/
|
|
192
|
-
├── database_dictionary.xlsx # Excel — Overview + one sheet per table
|
|
193
|
-
├── database_document.docx # Word document (all tables)
|
|
194
|
-
├── er_diagram.mmd # Mermaid ER diagram
|
|
211
|
+
├── database_dictionary.xlsx # Excel — Overview + ER Diagram + one sheet per table
|
|
212
|
+
├── database_document.docx # Word document (all tables + ER diagram)
|
|
213
|
+
├── er_diagram.mmd # Mermaid ER diagram (when `diagram` format is enabled)
|
|
214
|
+
├── er_diagram.png # PNG preview of ER diagram (excel/word/markdown/html)
|
|
215
|
+
├── ER_DIAGRAM.md # Standalone Mermaid ER diagram (markdown format)
|
|
195
216
|
├── tables/
|
|
196
217
|
│ ├── users.md # Per-table Markdown
|
|
197
218
|
│ └── orders.md
|
|
198
219
|
└── html/
|
|
199
220
|
├── index.html # Table list with links
|
|
221
|
+
├── er-diagram.html # Interactive Mermaid ER diagram page
|
|
200
222
|
└── tables/
|
|
201
223
|
├── users.html # Per-table HTML
|
|
202
224
|
└── orders.html
|
|
@@ -206,22 +228,28 @@ output/db_doc_gen_2606281947/
|
|
|
206
228
|
|
|
207
229
|
| Format | Output file(s) | Description |
|
|
208
230
|
| ------ | -------------- | ----------- |
|
|
209
|
-
| `excel` | `database_dictionary.xlsx` | A5:SQL-style workbook (
|
|
210
|
-
| `markdown` | `tables/<name>.md` | Per-table Markdown
|
|
211
|
-
| `html` | `html/index.html`, `html/tables/<name>.html` | Index page
|
|
212
|
-
| `diagram` | `er_diagram.mmd` | Mermaid `erDiagram` source |
|
|
213
|
-
| `word` | `database_document.docx` | Word document with all tables |
|
|
231
|
+
| `excel` | `database_dictionary.xlsx`, `er_diagram.png` | A5:SQL-style workbook with **Overview**, **ER Diagram** sheet (PNG + Mermaid source), and per-table sheets |
|
|
232
|
+
| `markdown` | `tables/<name>.md`, `ER_DIAGRAM.md` | Per-table Markdown + standalone Mermaid ER diagram file |
|
|
233
|
+
| `html` | `html/index.html`, `html/er-diagram.html`, `html/tables/<name>.html` | Index page, interactive Mermaid ER page, and per-table pages |
|
|
234
|
+
| `diagram` | `er_diagram.mmd` | Mermaid `erDiagram` source only |
|
|
235
|
+
| `word` | `database_document.docx`, `er_diagram.png` | Word document with overview, ER diagram section (PNG), and all tables |
|
|
214
236
|
|
|
215
237
|
### A5:SQL-style column definition
|
|
216
238
|
|
|
217
|
-
All text exporters (Excel, Markdown, HTML, Word) use the same
|
|
239
|
+
All text exporters (Excel, Markdown, HTML, Word) use the same ten-column definition table:
|
|
240
|
+
|
|
241
|
+
| Physical Name | Logical Name | Type | Size | Required | Default Value | Min | Max | Unique | Notes |
|
|
242
|
+
| ------------- | ------------ | ---- | ---- | -------- | ------------- | --- | --- | ------ | ----- |
|
|
243
|
+
| `id` | | `bigint` | | Yes | `-` | | | No | PK |
|
|
244
|
+
| `email` | | `varchar(255)` | `255` | Yes | `-` | | | Yes | |
|
|
245
|
+
| `age` | | `int` | | Yes | `-` | `0` | `150` | No | CHECK |
|
|
218
246
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
247
|
+
- **Size** — length/precision from the column type (e.g. `varchar(128)` → `128`, `numeric(12,2)` → `12,2`)
|
|
248
|
+
- **Min / Max** — extracted from `CHECK` constraints when possible (e.g. `age >= 0 AND age <= 150`)
|
|
249
|
+
- **Unique** — column-level `UNIQUE`, table `UNIQUE` constraints, and `UNIQUE` indexes
|
|
250
|
+
- **Notes** — PK/FK markers, `AUTO_INCREMENT`, `GENERATED` columns, `ENUM` values, composite `UNIQUE`, `CHECK` text, and other constraint hints
|
|
223
251
|
|
|
224
|
-
Column headers are localized based on `output.language` (e.g. Japanese: 物理名 | 論理名 | 型 | 必須 | デフォルト値 | 備考).
|
|
252
|
+
Column headers are localized based on `output.language` (e.g. Japanese: 物理名 | 論理名 | 型 | 桁数 | 必須 | デフォルト値 | 最小値 | 最大値 | 一意 | 備考).
|
|
225
253
|
|
|
226
254
|
### Excel workbook layout
|
|
227
255
|
|
|
@@ -233,6 +261,13 @@ Column headers are localized based on `output.language` (e.g. Japanese: 物理
|
|
|
233
261
|
- Hyperlinks from table names to their detail sheets
|
|
234
262
|
- Auto-filter enabled on the table list
|
|
235
263
|
|
|
264
|
+
**ER Diagram sheet**
|
|
265
|
+
|
|
266
|
+
- Title bar with ER diagram heading
|
|
267
|
+
- Embedded PNG preview (**ELK** layered layout + orthogonal routing; table boxes list PK/FK columns first)
|
|
268
|
+
- Full-resolution copy also written as `er_diagram.png` beside the workbook
|
|
269
|
+
- Mermaid source block below the image for copy/paste into Mermaid-compatible tools
|
|
270
|
+
|
|
236
271
|
**Per-table sheet**
|
|
237
272
|
|
|
238
273
|
- Title bar with table physical name
|
|
@@ -243,9 +278,23 @@ Column headers are localized based on `output.language` (e.g. Japanese: 物理
|
|
|
243
278
|
|
|
244
279
|
### HTML layout
|
|
245
280
|
|
|
246
|
-
- `html/index.html` — summary cards + sortable table list with links to each table
|
|
281
|
+
- `html/index.html` — summary cards + sortable table list with links to each table and ER diagram
|
|
282
|
+
- `html/er-diagram.html` — interactive Mermaid ER diagram with **pan, zoom, fit, reset** toolbar
|
|
247
283
|
- `html/tables/<name>.html` — metadata, column table, PK/FK row highlighting, back link to index
|
|
248
284
|
|
|
285
|
+
### ER diagram embedding
|
|
286
|
+
|
|
287
|
+
When you generate `excel`, `html`, `markdown`, or `word` output, an ER diagram is embedded automatically — you do not need to enable the `diagram` format separately.
|
|
288
|
+
|
|
289
|
+
| Output | ER diagram location |
|
|
290
|
+
| ------ | ------------------- |
|
|
291
|
+
| Excel | **ER Diagram** worksheet (ELK orthogonal PNG + Mermaid source text) |
|
|
292
|
+
| HTML | `html/er-diagram.html` (linked from index) |
|
|
293
|
+
| Markdown | `ER_DIAGRAM.md` (fenced `mermaid` block) |
|
|
294
|
+
| Word | ER Diagram section after overview (PNG + Mermaid source) |
|
|
295
|
+
|
|
296
|
+
The standalone `diagram` format still writes `er_diagram.mmd` for tooling that consumes raw Mermaid files.
|
|
297
|
+
|
|
249
298
|
### Output languages
|
|
250
299
|
|
|
251
300
|
| Language | Config value | Notes |
|
|
@@ -261,9 +310,10 @@ Set via config or ensure `output.language` is set before generation:
|
|
|
261
310
|
|
|
262
311
|
### Logical names and comments
|
|
263
312
|
|
|
264
|
-
**Logical Name**
|
|
313
|
+
- **Logical Name** — from SQL `COMMENT` on the column (empty → `(none)`)
|
|
314
|
+
- **Notes** — constraint metadata (PK, FK, `AUTO_INCREMENT`, `CHECK`, …), not the same as logical name
|
|
265
315
|
|
|
266
|
-
To populate
|
|
316
|
+
To populate logical names, add comments in your DDL:
|
|
267
317
|
|
|
268
318
|
```sql
|
|
269
319
|
CREATE TABLE users (
|
|
@@ -277,9 +327,10 @@ CREATE TABLE users (
|
|
|
277
327
|
```ts
|
|
278
328
|
import { generateDbDocs } from "@cuongph.dev/dbdocgen";
|
|
279
329
|
|
|
330
|
+
// API outDir is the exact run directory (no auto timestamp — create the path yourself if needed)
|
|
280
331
|
const doc = await generateDbDocs({
|
|
281
332
|
schema: "./database/schema.sql",
|
|
282
|
-
outDir: "./
|
|
333
|
+
outDir: "./output/db_doc_gen_manual",
|
|
283
334
|
dialect: "mysql", // optional — auto-detected if omitted
|
|
284
335
|
output: {
|
|
285
336
|
formats: ["excel", "markdown", "html", "diagram", "word"],
|
|
@@ -344,19 +395,21 @@ schema.sql
|
|
|
344
395
|
▼
|
|
345
396
|
Normalized Metadata Model (DatabaseDoc)
|
|
346
397
|
│
|
|
347
|
-
├──► Excel Exporter
|
|
348
|
-
├──► Markdown Exporter → tables/*.md
|
|
349
|
-
├──► HTML Exporter
|
|
350
|
-
├──► Mermaid Exporter → er_diagram.mmd
|
|
351
|
-
└──► Word Exporter → database_document.docx
|
|
398
|
+
├──► Excel Exporter → database_dictionary.xlsx + er_diagram.png
|
|
399
|
+
├──► Markdown Exporter → tables/*.md + ER_DIAGRAM.md
|
|
400
|
+
├──► HTML Exporter → html/index.html + html/er-diagram.html + html/tables/*.html
|
|
401
|
+
├──► Mermaid Exporter → er_diagram.mmd (optional `diagram` format)
|
|
402
|
+
└──► Word Exporter → database_document.docx + er_diagram.png
|
|
352
403
|
```
|
|
353
404
|
|
|
405
|
+
ER diagram PNG/SVG uses **elkjs** (orthogonal layout). Rasterization uses **sharp**.
|
|
406
|
+
|
|
354
407
|
### Metadata model
|
|
355
408
|
|
|
356
409
|
The internal `DatabaseDoc` structure contains:
|
|
357
410
|
|
|
358
411
|
- `dialect` — detected SQL dialect
|
|
359
|
-
- `tables[]` — table name, comment, columns
|
|
412
|
+
- `tables[]` — table name, comment, columns (`size`, `minValue`, `maxValue`, `isUnique`, `constraintNotes`, …), PK, FK, indexes
|
|
360
413
|
- `relationships[]` — FK relationships derived from schema
|
|
361
414
|
- `indexes[]` — standalone index definitions
|
|
362
415
|
- `warnings[]` — parser limitations, unsupported syntax
|
|
@@ -377,6 +430,8 @@ Schema facts (names, types, constraints) are never modified after parsing.
|
|
|
377
430
|
| SQL parser | node-sql-parser |
|
|
378
431
|
| Excel | exceljs |
|
|
379
432
|
| Word | docx |
|
|
433
|
+
| ER layout | elkjs |
|
|
434
|
+
| ER PNG | sharp |
|
|
380
435
|
| Tests | vitest |
|
|
381
436
|
| Lint / format | eslint, prettier |
|
|
382
437
|
|
|
@@ -388,15 +443,16 @@ src/
|
|
|
388
443
|
├── core/
|
|
389
444
|
│ ├── config/ # Config schema, loader, defaults
|
|
390
445
|
│ ├── model/ # DatabaseDoc types + Zod validation
|
|
446
|
+
│ ├── output-path.ts # db_doc_gen_* run directory helpers
|
|
391
447
|
│ └── pipeline/ # generateDbDocs orchestration
|
|
392
|
-
├── parsers/sql/ # SQL parser
|
|
448
|
+
├── parsers/sql/ # SQL parser, normalizer, column-meta
|
|
393
449
|
├── exporters/
|
|
394
450
|
│ ├── excel/ # A5-style Excel workbook
|
|
395
451
|
│ ├── markdown/ # Per-table Markdown
|
|
396
452
|
│ ├── html/ # Index + per-table HTML
|
|
397
|
-
│ ├── diagram/ # Mermaid ER
|
|
453
|
+
│ ├── diagram/ # Mermaid, ELK SVG/PNG, ER embed helpers
|
|
398
454
|
│ ├── word/ # Word document
|
|
399
|
-
│ └── shared/ # i18n
|
|
455
|
+
│ └── shared/ # i18n labels + A5 column-definition helpers
|
|
400
456
|
└── index.ts # Public API barrel
|
|
401
457
|
```
|
|
402
458
|
|
|
@@ -412,6 +468,8 @@ pnpm lint # eslint
|
|
|
412
468
|
pnpm format # prettier
|
|
413
469
|
```
|
|
414
470
|
|
|
471
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide on contributing and publishing to npm.
|
|
472
|
+
|
|
415
473
|
## Limitations
|
|
416
474
|
|
|
417
475
|
| Limitation | Notes |
|
|
@@ -421,7 +479,9 @@ pnpm format # prettier
|
|
|
421
479
|
| Dialect coverage | PostgreSQL and MySQL/MariaDB are primary targets |
|
|
422
480
|
| No incremental gen | Each run regenerates all output files |
|
|
423
481
|
| No web UI | Outputs are static files |
|
|
424
|
-
|
|
|
482
|
+
| Complex CHECK / ENUM | Simple bounds extracted; complex expressions may appear only in Notes |
|
|
483
|
+
| ER PNG in Excel | Large schemas show up to 6 key columns per table (PK/FK first); use HTML Mermaid for full interactive view |
|
|
484
|
+
| API vs CLI `outDir` | CLI appends `db_doc_gen_*` under parent; API `outDir` is the exact destination path |
|
|
425
485
|
|
|
426
486
|
## Roadmap
|
|
427
487
|
|