@zxsylph/dbml-formatter 1.0.10 → 1.0.11
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 +94 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @zxsylph/dbml-formatter
|
|
2
|
+
|
|
3
|
+
A powerful and flexible formatter for [DBML (Database Markup Language)](https://dbml.dbdiagram.io/home/) files. This tool helps keep your DBML schemas clean, consistent, and readable by applying standard formatting rules, alignment, and optional enhancements.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Standard Formatting**: Applies consistent spacing and indentation to tables, fields, indexes, and relationships.
|
|
8
|
+
- **Alignment**:
|
|
9
|
+
- Automatically aligns field data types for better readability.
|
|
10
|
+
- Aligns field settings (e.g., `[pk, increment]`) for a clean columnar look.
|
|
11
|
+
- **Field Sorting** (Optional): Sorts fields within groups alphabetically.
|
|
12
|
+
- **Note Management** (Optional): Automatically adds empty notes to fields and tables if they are missing.
|
|
13
|
+
- **Batch Processing**: Supports formatting individual files or entire directories recursively.
|
|
14
|
+
- **Dry Run**: Preview changes without modifying files.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
You can use the formatter directly via `npx` without installation:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx @zxsylph/dbml-formatter <file-or-options>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or install it globally:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g @zxsylph/dbml-formatter
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Format a Single File
|
|
33
|
+
|
|
34
|
+
Prints the formatted result to `stdout`.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx @zxsylph/dbml-formatter schema.dbml
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Format a Directory
|
|
41
|
+
|
|
42
|
+
Formats all `.dbml` files in the specified directory (and subdirectories) **in place**.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx @zxsylph/dbml-formatter --folder ./database
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Options & Flags
|
|
49
|
+
|
|
50
|
+
| Flag | Description |
|
|
51
|
+
| ----------------- | ---------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `--folder <path>` | Specifies a directory to recursively find and format `.dbml` files. Updates files in place. |
|
|
53
|
+
| `--dry-run` | Use with `--folder` to preview formatting changes in the console instead of overwriting files. |
|
|
54
|
+
| `--order-field` | Sorts fields within their logical groups (separated by blank lines) in ascending order. |
|
|
55
|
+
| `--add-note` | Automatically adds `Note: ''` to tables and fields that don't have one. |
|
|
56
|
+
|
|
57
|
+
### Examples
|
|
58
|
+
|
|
59
|
+
**1. Basic file formatting (output to console):**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx @zxsylph/dbml-formatter schema.dbml > formatted_schema.dbml
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**2. Format an entire project directory:**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx @zxsylph/dbml-formatter --folder ./src/db
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**3. Format with field sorting and extra notes:**
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npx @zxsylph/dbml-formatter --folder ./src/db --order-field --add-note
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**4. Preview changes for a folder:**
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx @zxsylph/dbml-formatter --folder ./src/db --dry-run
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Formatting Rules
|
|
84
|
+
|
|
85
|
+
The formatter applies the following styles:
|
|
86
|
+
|
|
87
|
+
- **Indentation**: 2 spaces.
|
|
88
|
+
- **Spacing**: Removes extra empty lines inside table bodies.
|
|
89
|
+
- **Alignment**: Vertically aligns data types and column settings `[...]`.
|
|
90
|
+
- **Hoisting**: Moves table-level notes to the top of the table definition.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
ISC
|