quickdbd-cli 0.3.2__py3-none-any.whl → 0.3.3__py3-none-any.whl

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.
quickdbd_cli/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.3.2"
1
+ __version__ = "0.3.3"
quickdbd_cli/agent.py CHANGED
@@ -638,12 +638,6 @@ def diff_schema(ws: Workspace, args: dict) -> Result:
638
638
  return Result("\n".join(clip(_header(c) + text.splitlines(), "lines")))
639
639
 
640
640
 
641
- def _svg_size(svg: str) -> tuple[float, float]:
642
- w = re.search(r'\bwidth="([\d.]+)', svg)
643
- h = re.search(r'\bheight="([\d.]+)', svg)
644
- return (float(w.group(1)) if w else 1000.0, float(h.group(1)) if h else 1000.0)
645
-
646
-
647
641
  def render_diagram(ws: Workspace, args: dict) -> Result:
648
642
  c = ws.compile(ws.target(args.get("project")))
649
643
  tables = selected(c, args.get("select"))
@@ -679,7 +673,7 @@ def render_diagram(ws: Workspace, args: dict) -> Result:
679
673
  raise ToolError("the layout took too long; narrow with `select` or `focus`") from None
680
674
  pos = {k: [v[0], v[1]] for k, v in laid.items()}
681
675
  svg = export.render_svg(c.model, pos, only=ids, mode=mode, embed_font=False)
682
- scale = min(2.0, IMAGE_SIDE / max(_svg_size(svg)))
676
+ scale = min(2.0, IMAGE_SIDE / max(export.svg_size(svg)))
683
677
  if scale >= MIN_SCALE[mode]:
684
678
  png = export.svg_to_png(svg, scale)
685
679
  names = ", ".join(t["name"] for t in tables[:40]) + (", …" if n > 40 else "")
@@ -82,6 +82,7 @@ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
82
82
  #stage { position: relative; flex: 1; overflow: hidden; }
83
83
  #canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
84
84
  #canvas.panning { cursor: grabbing; }
85
+ #canvas.lod .t text { display: none; } /* big diagram, zoomed out: see LOD_TABLES in viewer.js */
85
86
 
86
87
  /* diagram colours: CSS beats the SVG presentation attributes, so the page can theme them */
87
88
  .tb { fill: var(--t-body); stroke: var(--t-border); }
@@ -40,9 +40,13 @@
40
40
  applyFocus();
41
41
  }
42
42
 
43
+ // Zoomed out on a big diagram, table text is unreadable but repainting it made every zoom step take ~150 ms
44
+ // at 1000 tables, so it is hidden there. Smaller diagrams always show it.
45
+ var LOD_TABLES = 300, LOD_ZOOM = 0.3;
43
46
  function applyView() {
44
47
  var v = S.view;
45
48
  vp.setAttribute("transform", "translate(" + v.x + "," + v.y + ") scale(" + v.k + ")");
49
+ svg.classList.toggle("lod", v.k < LOD_ZOOM && S.vm.tables.length > LOD_TABLES);
46
50
  zoomval.textContent = Math.round(v.k * 100) + "%";
47
51
  drawViewportRect();
48
52
  scheduleHash();
@@ -806,7 +810,7 @@
806
810
  try {
807
811
  if (p.has("m")) setMode(p.get("m"));
808
812
  if (p.has("r")) setRegions(p.get("r") === "1");
809
- applyFilter(p.get("f") || "", true);
813
+ if ((p.get("f") || "") !== S.filter) applyFilter(p.get("f") || "", true); // else already rendered
810
814
  var name = p.get("t"), id = null;
811
815
  if (name) S.model.tables.forEach(function (t) { if (t.name === name) id = t.id; });
812
816
  select(id && S.shown[id] ? id : null);
quickdbd_cli/cli.py CHANGED
@@ -216,7 +216,11 @@ def cmd_export(args) -> int:
216
216
  if fmt == "svg":
217
217
  out.write_text(svg, encoding="utf-8")
218
218
  else:
219
- out.write_bytes(export.svg_to_png(svg, args.scale))
219
+ scale = export.png_scale(svg, args.scale)
220
+ if scale < args.scale:
221
+ note = f"--scale lowered to {scale:.2f} to keep the PNG within {export.MAX_PNG_SIDE} px"
222
+ print(f"note: {note}", file=sys.stderr)
223
+ out.write_bytes(export.svg_to_png(svg, scale))
220
224
  print(f"Wrote {out} ({len(only) if only else len(model['tables'])} tables)")
221
225
  return 0
222
226
 
@@ -532,7 +536,7 @@ def build_parser() -> argparse.ArgumentParser:
532
536
  action="append",
533
537
  metavar="SELECTOR",
534
538
  help="dbt-style: name glob, +name (and what it references), name+ (and what references it), "
535
- "N+name+N (hops), group:/file:/col: methods, a,b intersects (repeatable)",
539
+ "N+name+N (hops), group:/file:/col:/tag: methods, a,b intersects (repeatable)",
536
540
  )
537
541
  sp.add_argument("--exclude", action="append", metavar="SELECTOR", help="drop tables matching (repeatable)")
538
542
 
quickdbd_cli/export.py CHANGED
@@ -3,12 +3,16 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import base64
6
+ import re
6
7
  from functools import cache
7
8
  from importlib import resources
8
9
 
9
10
  from . import layout
10
11
  from .jsrt import runtime
11
12
 
13
+ # A 200-table diagram at scale 2 is 17506x15274 px: 15 s to encode, and too big for many image viewers.
14
+ MAX_PNG_SIDE = 16384
15
+
12
16
 
13
17
  def _asset_bytes(name: str) -> bytes:
14
18
  return resources.files("quickdbd_cli").joinpath(f"assets/{name}").read_bytes()
@@ -85,6 +89,17 @@ def focus_positions(model: dict, positions: dict, ids: list[str]) -> dict:
85
89
  return {k: [v[0], v[1]] for k, v in pos.items()}
86
90
 
87
91
 
92
+ def svg_size(svg: str) -> tuple[float, float]:
93
+ w = re.search(r'\bwidth="([\d.]+)', svg)
94
+ h = re.search(r'\bheight="([\d.]+)', svg)
95
+ return (float(w.group(1)) if w else 1000.0, float(h.group(1)) if h else 1000.0)
96
+
97
+
98
+ def png_scale(svg: str, scale: float) -> float:
99
+ """``scale``, lowered so the PNG's longest side stays within MAX_PNG_SIDE pixels."""
100
+ return min(scale, MAX_PNG_SIDE / max(svg_size(svg)))
101
+
102
+
88
103
  def svg_to_png(svg: str, scale: float = 2.0) -> bytes:
89
104
  import resvg_py
90
105
 
quickdbd_cli/layout.py CHANGED
@@ -32,6 +32,10 @@ OVERLAP_OPTIONS = {
32
32
  "elk.spacing.nodeNode": "40",
33
33
  "elk.randomSeed": "1",
34
34
  }
35
+ # Overlap removal takes most of a big layout (25 of 37 s at 1000 tables). Above BIG_LAYOUT tables its
36
+ # iterations are capped, and the few tables it leaves overlapping are moved by `_separate`.
37
+ BIG_LAYOUT = 300
38
+ BIG_OVERLAP_OPTIONS = {**OVERLAP_OPTIONS, "org.eclipse.elk.overlapRemoval.maxIterations": "8"}
35
39
 
36
40
  MARGIN = 30
37
41
  Positions = dict[str, tuple[int, int]]
@@ -64,9 +68,10 @@ def elk_layout(tables: list[dict], rels: list[dict], timeout_sec: float | None =
64
68
  }
65
69
  first = rt.call_async("qdbdElkLayout", graph, timeout_sec=timeout_sec)
66
70
  first = _landscape(tables, {k: (v[0], v[1]) for k, v in first.items()})
71
+ big = len(tables) > BIG_LAYOUT
67
72
  graph = {
68
73
  "id": "root",
69
- "layoutOptions": OVERLAP_OPTIONS,
74
+ "layoutOptions": BIG_OVERLAP_OPTIONS if big else OVERLAP_OPTIONS,
70
75
  "children": [
71
76
  {"id": t["id"], "width": t["w"], "height": t["h"], "x": first[t["id"]][0], "y": first[t["id"]][1]}
72
77
  for t in tables
@@ -74,6 +79,8 @@ def elk_layout(tables: list[dict], rels: list[dict], timeout_sec: float | None =
74
79
  "edges": [],
75
80
  }
76
81
  raw = rt.call_async("qdbdElkLayout", graph, timeout_sec=timeout_sec)
82
+ if big:
83
+ raw = _separate(tables, raw)
77
84
  min_x = min(v[0] for v in raw.values())
78
85
  min_y = min(v[1] for v in raw.values())
79
86
  return {k: (int(v[0] - min_x), int(v[1] - min_y)) for k, v in raw.items()}
@@ -155,6 +162,18 @@ def _free_spot(cx: float, cy: float, w: float, h: float, rects, step: int = 30)
155
162
  return int(round(x0)), int(round(y0))
156
163
 
157
164
 
165
+ def _separate(tables: list[dict], pos: dict) -> dict:
166
+ """Move each table that overlaps an earlier one to the nearest free spot."""
167
+ out, rects = {}, []
168
+ for t in tables:
169
+ x, y = pos[t["id"]]
170
+ if _overlaps(x, y, t["w"], t["h"], rects):
171
+ x, y = _free_spot(x + t["w"] / 2, y + t["h"] / 2, t["w"], t["h"], rects)
172
+ out[t["id"]] = (x, y)
173
+ rects.append((x, y, t["w"], t["h"]))
174
+ return out
175
+
176
+
158
177
  def place_missing(tables: list[dict], rels: list[dict], positions: Positions) -> Positions:
159
178
  """Positions for every table. Existing positions never move.
160
179
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: quickdbd-cli
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Compile QuickDBD-syntax schema files into interactive HTML ER diagrams, with no table limit.
5
5
  Project-URL: Homepage, https://qdbd.dev/
6
6
  Project-URL: Documentation, https://qdbd.dev/guide/
@@ -43,7 +43,7 @@ Description-Content-Type: text/markdown
43
43
  </picture>
44
44
  </p>
45
45
 
46
- <p align="center"><b>Interactive ER diagrams from QuickDBD text or a dbt project, readable at 200+ tables</b></p>
46
+ <p align="center"><b>Interactive ER diagrams from QuickDBD text, DBML or a dbt project, readable at 200+ tables</b></p>
47
47
 
48
48
  <p align="center">
49
49
  <a href="https://pypi.org/project/quickdbd-cli/"><img src="https://img.shields.io/pypi/v/quickdbd-cli?label=PyPI" alt="PyPI version"></a>
@@ -89,7 +89,7 @@ qdbd is not affiliated with QuickDBD or dbdiagram.io. It reads the same text syn
89
89
  - **QuickDBD-compatible**: the parser mirrors QuickDBD's own, error messages included. A file that passes `qdbd check --strict` pastes into QuickDBD unchanged.
90
90
  - **dbt import**: `qdbd import dbt` reads `manifest.json`. Primary keys come from `unique` + `not_null` tests or constraints, relationships from `relationships` tests, and `--infer-fks` fills the gaps from column names.
91
91
  - **Readable at 200+ tables**: automatic layout, search, dbt-style selectors (`+orders+1`, `group:marts`, `tag:fact`), shaded regions per file, collapsed views and a minimap.
92
- - **Review changes in pull requests**: `qdbd diff` reports what a branch changed, the GitHub Action posts it as a PR comment, and `--diff-base` colours the changes in the diagram.
92
+ - **Review changes in pull requests**: `qdbd diff` reports what a branch changed, the GitHub Action posts it as a PR comment, and `--diff-base` colours the changes in the diagram. To propose a column change, tag the column `# @tag: added` or `# @tag: removed` and it's drawn green or red ([column tags](https://qdbd.dev/tags/#columns)).
93
93
  - **VS Code extension**: highlighting, errors as you type, outline, F12 across files, and the diagram beside the editor, following your cursor, or in your browser on localhost. Export, share, compare with git, convert to and from DBML, and dbt import from the sidebar or the Command Palette, with no terminal: it installs the CLI itself. Get it from the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=MarkPhamm.quickdbd) or, for Cursor, Windsurf and VSCodium, [Open VSX](https://open-vsx.org/extension/MarkPhamm/quickdbd) ([docs](https://qdbd.dev/vscode/)).
94
94
  - **AI agents**: `qdbd mcp` gives Claude, Copilot and Cursor your schema as tools: tables and columns, join paths as SQL (composite keys included), checks for their edits and diffs against `main` ([docs](https://qdbd.dev/mcp/)).
95
95
  - **One schema, many outputs**: an HTML page, PNG, SVG, editable draw.io, or a shareable link. Installs with pip: no Node, Graphviz or browser needed.
@@ -186,7 +186,7 @@ jobs:
186
186
  permissions: { contents: read, pull-requests: write }
187
187
  steps:
188
188
  - uses: actions/checkout@v4
189
- - uses: MarkPhamm/quickdbd-cli@v0.1.11
189
+ - uses: MarkPhamm/quickdbd-cli@v0.3.3
190
190
  with:
191
191
  path: erd/ # schema file(s) or folder(s)
192
192
  output: site/index.html
@@ -198,7 +198,7 @@ dbt projects, GitHub Pages, pre-commit and GitLab CI are covered in [CI and Auto
198
198
 
199
199
  ```text
200
200
  dbt project ──qdbd import dbt──┐
201
- ├──▶ schema/*.txt (QuickDBD syntax, in git)
201
+ ├──▶ schema/*.txt, *.dbml (QuickDBD syntax or DBML, in git)
202
202
  hand-written / pasted ─────────┘ │
203
203
  ├──▶ qdbd check validation, QuickDBD's error messages ──▶ CI gate
204
204
  ├──▶ qdbd serve live editor, drag to arrange ──▶ schema.layout.json
@@ -240,7 +240,7 @@ qdbd build schema/ -o erd.html
240
240
 
241
241
  | | qdbd | QuickDBD |
242
242
  |---|---|---|
243
- | Text syntax | QuickDBD's | QuickDBD's |
243
+ | Text syntax | QuickDBD's or DBML | QuickDBD's |
244
244
  | Tables per diagram | no limit | 10 on the free plan |
245
245
  | Where it runs | your terminal and CI; the result is a static HTML file | the QuickDBD web app |
246
246
  | Where the schema lives | `.txt` / `.dbml` files in your git repo | the web app |
@@ -1,15 +1,15 @@
1
- quickdbd_cli/__init__.py,sha256=vNiWJ14r_cw5t_7UDqDQIVZvladKFGyHH2avsLpN7Vg,22
1
+ quickdbd_cli/__init__.py,sha256=8KcCYTXH99C2-gCLuPILJvtT9YftRWJsartIx6TQ2ZY,22
2
2
  quickdbd_cli/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
3
- quickdbd_cli/agent.py,sha256=pZzKc9DMqN6pX1ZzXgcb11ZqX91wuJZW1f6xO2uGc2M,37421
4
- quickdbd_cli/cli.py,sha256=GJnOpXVwEpJHUQkagGrMc27x5vt1N6Ybj1-tX-TLPzE,29288
3
+ quickdbd_cli/agent.py,sha256=LEuReTkwWDlRLs-GfQQMpMosHDFWbin0EAXRo73j-dA,37202
4
+ quickdbd_cli/cli.py,sha256=h9pTnGnprYOhyuEpjdd32QyAqR-skJRTBvoipIyCZS0,29522
5
5
  quickdbd_cli/convert.py,sha256=1AYFm4YmEav_wZp7xCAcL7TsD3qC17Y1I5g6V_fyAU0,16682
6
6
  quickdbd_cli/dbml.py,sha256=tHJOtMm1PHx4-yqs6rncPqdDfbwPcW8F54j_kKlWkx0,59413
7
7
  quickdbd_cli/dbt.py,sha256=AMHzERmc8WfL1tBLX4bJdPVghIHrqrfx8nMDbZMrueY,23100
8
8
  quickdbd_cli/diff.py,sha256=UBiCE3dk_cN-xSRZFQoLiIIFh_FAVZUpLwsdtHG9eBo,9986
9
- quickdbd_cli/export.py,sha256=pjWe3oloaxVkV2b96GllQR4faB9OMtbNuTscxwjQhsk,2983
9
+ quickdbd_cli/export.py,sha256=XbSvWqFmhQHPcBtPHPit1SmhJ6qXrPyGlHYt7FpIMyo,3539
10
10
  quickdbd_cli/html.py,sha256=fiMsBPkBiCpxz-8x4_SFaeejdnHCAAK0IVlrimbpS5I,7950
11
11
  quickdbd_cli/jsrt.py,sha256=_sRkmUbgHDTwK272jeTNUwojfjUKAkv4UeD2E2u3H1A,3464
12
- quickdbd_cli/layout.py,sha256=ajzJCJQ8ofnYj8dhz8aWq-LV2tmW5BHwJQ2LRoeSWaM,9998
12
+ quickdbd_cli/layout.py,sha256=2wrryJ-SSJbMlOdxmtCTzC2_zkTtvRVs-OuOBS1bGEQ,10856
13
13
  quickdbd_cli/mcp.py,sha256=ibUg1a50BBco-hZABdxTexGZi_gclFCdcBDalTvFar8,12350
14
14
  quickdbd_cli/measure.py,sha256=Nyk47FiJokPvTStKz23mgXkO0HnXKWOts90kp1gCjng,5969
15
15
  quickdbd_cli/model.py,sha256=lQcj89gDg2y4v_xhJX0_PWoWKGx0rg2emREVL_LA6uQ,3352
@@ -29,14 +29,14 @@ quickdbd_cli/assets/elk-LICENSE.md,sha256=Y36B9KG2tAeVNcSZ_KBeI4z3YFwf9bdtYNfafO
29
29
  quickdbd_cli/assets/elk.bundled.js,sha256=EiLkT5U853Rq8jgB5yNwj45vQ2uLN3pqX8dVLzSjB7M,1609707
30
30
  quickdbd_cli/assets/font-metrics.json,sha256=sXSiElxQSK8md8IEePLwh16TTdAqKt9rV140pvMlVS8,8654
31
31
  quickdbd_cli/assets/render.js,sha256=3Jv7On2X9MghnP-GInfkkfsBFgMC1vg6VkpYfOzgjwM,28944
32
- quickdbd_cli/assets/style.css,sha256=HDF9tWXoQ0DRhSCiSmMDaXysK0Wd0VWW4_iwKgQdLFg,16185
32
+ quickdbd_cli/assets/style.css,sha256=aKIzW8z2V_khDSH7gJ42jisNxnFOKQTKBOuN1YiPt28,16283
33
33
  quickdbd_cli/assets/syntax-reference.md,sha256=WERcsWjyrfeHQPgxQriWKBsqFJnmWTQ2oRZjKYAHhKc,5322
34
- quickdbd_cli/assets/viewer.js,sha256=T7AD6qQ3GmHN4iL8MX19GZ_kQO46hfPsJp7AsMYyRYU,39683
35
- quickdbd_cli-0.3.2.dist-info/METADATA,sha256=3Qc1utZqKyjVciyy0ZvUH-0ADh_OlH817rA9ZK9TbZw,17009
36
- quickdbd_cli-0.3.2.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
37
- quickdbd_cli-0.3.2.dist-info/entry_points.txt,sha256=nRhiYYug-XOY95nWUmi4oanico3Zjkfqk2OHtIE6SQ0,47
38
- quickdbd_cli-0.3.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
39
- quickdbd_cli-0.3.2.dist-info/licenses/NOTICE,sha256=pyv3BfIYiGzKLU4w-GcBe7GXoXxHqZ97Mf6Zpx_3_i0,2067
40
- quickdbd_cli-0.3.2.dist-info/licenses/src/quickdbd_cli/assets/Inter-LICENSE.txt,sha256=JiSB6ERSGzJvXs0FPlm5jIstp4yO4b27boF0MF5Uk1o,4380
41
- quickdbd_cli-0.3.2.dist-info/licenses/src/quickdbd_cli/assets/elk-LICENSE.md,sha256=Y36B9KG2tAeVNcSZ_KBeI4z3YFwf9bdtYNfafOlnAMk,14443
42
- quickdbd_cli-0.3.2.dist-info/RECORD,,
34
+ quickdbd_cli/assets/viewer.js,sha256=iKZBevQusb--Ysm3VPO3zaNAtesYOGjFWbevQ1JwBGU,40057
35
+ quickdbd_cli-0.3.3.dist-info/METADATA,sha256=SgSNj1SP_ZSB2LAQFWN4P01B2cGYPKJ8SDouUAZtsnA,17195
36
+ quickdbd_cli-0.3.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
37
+ quickdbd_cli-0.3.3.dist-info/entry_points.txt,sha256=nRhiYYug-XOY95nWUmi4oanico3Zjkfqk2OHtIE6SQ0,47
38
+ quickdbd_cli-0.3.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
39
+ quickdbd_cli-0.3.3.dist-info/licenses/NOTICE,sha256=pyv3BfIYiGzKLU4w-GcBe7GXoXxHqZ97Mf6Zpx_3_i0,2067
40
+ quickdbd_cli-0.3.3.dist-info/licenses/src/quickdbd_cli/assets/Inter-LICENSE.txt,sha256=JiSB6ERSGzJvXs0FPlm5jIstp4yO4b27boF0MF5Uk1o,4380
41
+ quickdbd_cli-0.3.3.dist-info/licenses/src/quickdbd_cli/assets/elk-LICENSE.md,sha256=Y36B9KG2tAeVNcSZ_KBeI4z3YFwf9bdtYNfafOlnAMk,14443
42
+ quickdbd_cli-0.3.3.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any