dbml-metaquery 0.1.0
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 +117 -0
- package/dist/cli.js +17445 -0
- package/dist/cli.js.map +32 -0
- package/dist/graph.d.ts +45 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17215 -0
- package/dist/index.js.map +31 -0
- package/dist/types.d.ts +63 -0
- package/package.json +44 -0
- package/src/cli.ts +271 -0
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# dbml-metaquery
|
|
2
|
+
|
|
3
|
+
Parse DBML into a navigable graph with rich metadata -- FK path finding, table info, groups, and schema search.
|
|
4
|
+
|
|
5
|
+
Uses `@dbml/parse` for correct handling of all DBML syntax.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install dbml-metaquery
|
|
11
|
+
# or
|
|
12
|
+
bun add dbml-metaquery
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Library API
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { DbmlGraph } from "dbml-metaquery"
|
|
19
|
+
import { readFileSync } from "fs"
|
|
20
|
+
|
|
21
|
+
const dbml = readFileSync("model.dbml", "utf-8")
|
|
22
|
+
const graph = new DbmlGraph(dbml)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Path Finding
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
graph.findPath("order_items", "users")
|
|
29
|
+
// [
|
|
30
|
+
// { from: { table: "order_items", column: "order_id" }, to: { table: "orders", column: "id" } },
|
|
31
|
+
// { from: { table: "orders", column: "user_id" }, to: { table: "users", column: "id" } },
|
|
32
|
+
// ]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Table Metadata
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
graph.getTable("orders")
|
|
39
|
+
// {
|
|
40
|
+
// name: "orders",
|
|
41
|
+
// note: "Customer orders",
|
|
42
|
+
// columns: [
|
|
43
|
+
// { name: "id", type: "INTEGER" },
|
|
44
|
+
// { name: "user_id", type: "INTEGER", fk: { table: "users", column: "id" } },
|
|
45
|
+
// { name: "product", type: "VARCHAR", note: "Product name" },
|
|
46
|
+
// ...
|
|
47
|
+
// ]
|
|
48
|
+
// }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Navigation
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// What tables reference users?
|
|
55
|
+
graph.getReferencingTables("users")
|
|
56
|
+
// [{ table: "orders", column: "user_id", myColumn: "id" }, ...]
|
|
57
|
+
|
|
58
|
+
// What's directly connected to orders?
|
|
59
|
+
graph.getNeighbors("orders")
|
|
60
|
+
// {
|
|
61
|
+
// parents: [{ table: "users", via: "user_id" }],
|
|
62
|
+
// children: [{ table: "order_items", via: "order_id" }]
|
|
63
|
+
// }
|
|
64
|
+
|
|
65
|
+
// Schema overview
|
|
66
|
+
graph.getSummary()
|
|
67
|
+
// [{ name: "people", tableCount: 2, tables: ["users", "departments"] }, ...]
|
|
68
|
+
|
|
69
|
+
// Search across table/column names and notes
|
|
70
|
+
graph.searchSchema("order")
|
|
71
|
+
// [{ table: "orders", match: "table_name", text: "orders" }, ...]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Groups and Colors
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
graph.getGroups() // all TableGroups with member tables
|
|
78
|
+
graph.getGroup("users") // { name: "people", tables: ["users", "departments"] }
|
|
79
|
+
graph.getTableColor("users") // "#3498db"
|
|
80
|
+
graph.getGroupColor("people") // "#3498db"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### All Methods
|
|
84
|
+
|
|
85
|
+
| Method | Returns | Description |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| `findPath(from, to)` | `PathStep[] \| null` | Shortest FK path between two tables |
|
|
88
|
+
| `getTables()` | `string[]` | All table names, sorted |
|
|
89
|
+
| `getRelationships(table?)` | `Relationship[]` | FK relationships, optionally filtered |
|
|
90
|
+
| `getTable(name)` | `TableInfo \| undefined` | Table note, columns with types/notes/FKs |
|
|
91
|
+
| `getGroups()` | `GroupInfo[]` | All TableGroups with member tables |
|
|
92
|
+
| `getGroup(tableName)` | `GroupInfo \| undefined` | Which group a table belongs to |
|
|
93
|
+
| `getTableColor(name)` | `string \| undefined` | Table headercolor |
|
|
94
|
+
| `getGroupColor(name)` | `string \| undefined` | Group color |
|
|
95
|
+
| `getReferencingTables(name)` | `ReferencingTable[]` | Tables that FK into this table |
|
|
96
|
+
| `getNeighbors(name)` | `Neighbors` | One-hop parents and children |
|
|
97
|
+
| `getSummary()` | `GroupSummary[]` | Groups with table counts |
|
|
98
|
+
| `searchSchema(query)` | `SearchResult[]` | Substring search across names and notes |
|
|
99
|
+
|
|
100
|
+
## CLI
|
|
101
|
+
|
|
102
|
+
The first argument is always the path to a `.dbml` file, followed by a command.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
dbml-metaquery model.dbml find-path <from> <to> # Shortest FK path
|
|
106
|
+
dbml-metaquery model.dbml info <table> # Table metadata
|
|
107
|
+
dbml-metaquery model.dbml neighbors <table> # Directly connected tables
|
|
108
|
+
dbml-metaquery model.dbml refs-to <table> # Tables that FK into this table
|
|
109
|
+
dbml-metaquery model.dbml rels <table> # All FK relationships
|
|
110
|
+
dbml-metaquery model.dbml search <query> # Search names and notes
|
|
111
|
+
dbml-metaquery model.dbml summary # Schema overview
|
|
112
|
+
dbml-metaquery model.dbml tables # List all tables
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|