quickdbd-cli 0.1.2__py3-none-any.whl → 0.1.4__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.1.2"
1
+ __version__ = "0.1.4"
@@ -18,6 +18,8 @@
18
18
  badgeBg: "#eef1f5",
19
19
  badgeText: "#7a8899",
20
20
  edge: "#b8bcc2",
21
+ added: "#2e7d32",
22
+ changed: "#d48806",
21
23
  };
22
24
  var FONT = "Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif";
23
25
 
@@ -76,7 +78,12 @@
76
78
  var st = model.style, w = g.w, h = g.h, out = [];
77
79
  out.push('<g class="t" data-id="' + esc(t.id) + '" transform="translate(' + n(p[0]) + "," + n(p[1]) + ')">');
78
80
  out.push('<rect class="tb" width="' + w + '" height="' + h + '" rx="2" fill="' + C.body + '" stroke="' + C.border + '"/>');
79
- out.push('<path class="th" d="M0 2a2 2 0 0 1 2-2h' + (w - 4) + "a2 2 0 0 1 2 2v" + (st.headerH - 2) + "h-" + w + 'z" fill="' + C.header + '"/>');
81
+ var state = t.diff && t.diff.state, hcol = state === "added" ? C.added : state === "changed" ? C.changed : C.header;
82
+ out.push('<path class="th" d="M0 2a2 2 0 0 1 2-2h' + (w - 4) + "a2 2 0 0 1 2 2v" + (st.headerH - 2) + "h-" + w + 'z" fill="' + hcol + '"/>');
83
+ if (state) {
84
+ out.push('<text x="' + (w - st.padX) + '" y="' + n(st.headerH / 2 + 4) + '" text-anchor="end" fill="#fff" font-family="' + FONT +
85
+ '" font-size="10" font-weight="bold">' + (state === "added" ? "NEW" : "CHANGED") + "</text>");
86
+ }
80
87
  out.push('<text x="' + st.padX + '" y="' + n(st.headerH / 2 + st.headerSize * 0.36) + '" fill="' + C.headerText +
81
88
  '" font-family="' + FONT + '" font-size="' + st.headerSize + '">' + esc(t.name) + "</text>");
82
89
  if (docMarks && t.doc) {
@@ -88,6 +95,8 @@
88
95
  var color = c.pk ? C.pk : c.fk ? C.fk : C.text;
89
96
  out.push('<g class="r" data-c="' + esc(c.id) + '">');
90
97
  out.push('<rect class="rb" y="' + y + '" width="' + w + '" height="' + st.rowH + '" fill="' + C.body + '" fill-opacity="0"/>');
98
+ var cstate = t.diff && t.diff.cols && t.diff.cols[c.id];
99
+ if (cstate) out.push('<rect y="' + (y + 3) + '" width="3" height="' + (st.rowH - 6) + '" fill="' + C[cstate] + '"/>');
91
100
  out.push('<text x="' + st.padX + '" y="' + base + '" fill="' + color + '" font-family="' + FONT + '" font-size="' +
92
101
  st.rowSize + '"' + weight + ">" + esc(c.name) + "</text>");
93
102
  if (docMarks && c.doc) out.push(docMark(st.padX, cy + st.rowSize * 0.36 + 2.5, c.nameW, color));
@@ -99,7 +108,7 @@
99
108
  '" font-family="' + FONT + '" font-size="' + st.badgeSize + '">' + esc(b.t) + "</text>");
100
109
  bx += b.w + st.badgeGap;
101
110
  });
102
- if (c.pk) out.push(keyIcon(w - st.padX - c.typeW - st.keyW + 1, cy));
111
+ if (c.pk) out.push(keyIcon(w - st.padX - c.typeW - st.keyW, cy));
103
112
  out.push('<text x="' + (w - st.padX) + '" y="' + base + '" text-anchor="end" fill="' + C.type + '" font-family="' + FONT +
104
113
  '" font-size="' + st.rowSize + '">' + esc(c.type) + "</text>");
105
114
  out.push("</g>");
@@ -225,7 +234,153 @@
225
234
  return out;
226
235
  }
227
236
 
237
+ /* ------------------------------------------------------------------ draw.io export
238
+ * mxGraph XML using draw.io's own Entity Relation table shapes, so tables stay editable
239
+ * (rows can be added, lines re-attached) and crow's-foot arrows are draw.io's ER arrows. */
240
+ var DRAWIO_ARROW = { one: "ERmandOne", many: "ERmany", zeroOne: "ERzeroToOne", zeroMany: "ERzeroToMany" };
241
+ function renderDrawio(model, pos, opts) {
242
+ opts = opts || {};
243
+ var mode = opts.mode || "full", m = subset(model, opts.only), geo = geometry(m, mode);
244
+ var KEYW = 44, ROWH = 26, HEADH = 32, cells = [], rowId = {}, n = 2;
245
+ function id() { return "q" + n++; }
246
+ function cell(attrs, geom) {
247
+ var a = Object.keys(attrs).map(function (k) { return k + '="' + esc(attrs[k]) + '"'; }).join(" ");
248
+ return "<mxCell " + a + ">" + geom + "</mxCell>";
249
+ }
250
+ function g(x, y, w, h) {
251
+ return '<mxGeometry x="' + n2(x) + '" y="' + n2(y) + '" width="' + n2(w) + '" height="' + n2(h) + '" as="geometry"/>';
252
+ }
253
+ function n2(v) { return Math.round(v); }
254
+ var b = bounds(m, pos, mode);
255
+ m.tables.forEach(function (t) {
256
+ var p = pos[t.id];
257
+ if (!p) return;
258
+ var tg = geo[t.id], w = tg.w + KEYW, tid = id();
259
+ rowId[t.id] = { _table: tid };
260
+ cells.push(cell({
261
+ id: tid, value: t.name, vertex: "1", parent: "1",
262
+ style: "shape=table;startSize=" + HEADH + ";container=1;collapsible=1;childLayout=tableLayout;fixedRows=1;rowLines=0;" +
263
+ "fontStyle=1;align=left;spacingLeft=10;resizeLast=1;html=0;whiteSpace=wrap;fillColor=#2b5797;fontColor=#ffffff;" +
264
+ "strokeColor=#dfe3e8;swimlaneFillColor=#ffffff;fontSize=14;",
265
+ }, g(p[0] - b[0] + 40, p[1] - b[1] + 40, w, HEADH + Math.max(tg.cols.length, 0) * ROWH)));
266
+ tg.cols.forEach(function (c, i) {
267
+ var rid = id(), key = c.pk && c.fk ? "PK,FK" : c.pk ? "PK" : c.fk ? "FK" : "";
268
+ rowId[t.id][c.id] = rid;
269
+ cells.push(cell({
270
+ id: rid, value: "", vertex: "1", parent: tid,
271
+ style: "shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;collapsible=0;" +
272
+ "dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;top=0;left=0;right=0;bottom=0;",
273
+ }, g(0, HEADH + i * ROWH, w, ROWH)));
274
+ var base = "shape=partialRectangle;connectable=0;fillColor=none;top=0;left=0;bottom=0;right=0;overflow=hidden;html=0;";
275
+ var flags = c.badges.map(function (x) { return x.t; }).join(" ");
276
+ cells.push(cell({ id: id(), value: key, vertex: "1", parent: rid, style: base + "fontStyle=1;fontColor=#2b5797;align=center;fontSize=11;" },
277
+ g(0, 0, KEYW, ROWH)));
278
+ cells.push(cell({
279
+ id: id(), value: c.name + (flags ? " [" + flags + "]" : "") + (c.type ? " : " + c.type : ""), vertex: "1", parent: rid,
280
+ style: base + "align=left;spacingLeft=6;fontSize=12;" + (c.pk ? "fontStyle=5;" : c.fk ? "fontStyle=1;" : ""),
281
+ }, g(KEYW, 0, w - KEYW, ROWH)));
282
+ });
283
+ });
284
+ m.rels.forEach(function (r) {
285
+ var ra = rowId[r.a.t], rb = rowId[r.b.t];
286
+ if (!ra || !rb) return;
287
+ var src = ra[r.a.c] || ra._table, dst = rb[r.b.c] || rb._table;
288
+ cells.push(cell({
289
+ id: id(), value: "", edge: "1", parent: "1", source: src, target: dst,
290
+ style: "edgeStyle=entityRelationEdgeStyle;fontSize=12;html=0;endFill=0;startFill=0;strokeColor=#9aa0a6;" +
291
+ "startArrow=" + DRAWIO_ARROW[r.a.card] + ";endArrow=" + DRAWIO_ARROW[r.b.card] + ";",
292
+ }, '<mxGeometry relative="1" as="geometry"/>'));
293
+ });
294
+ return '<mxfile host="qdbd" type="device"><diagram id="erd" name="' + esc(opts.title || "ERD") + '">' +
295
+ '<mxGraphModel dx="1200" dy="800" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" ' +
296
+ 'page="0" pageScale="1" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/>' +
297
+ cells.join("") + "</root></mxGraphModel></diagram></mxfile>";
298
+ }
299
+
300
+ /* ------------------------------------------------------------------ selectors (dbt-style, over relationships)
301
+ * Space-separated atoms are unioned; a comma inside an atom intersects (a,b); a leading ! excludes.
302
+ * Atom: [N]+ method:pattern +[N]
303
+ * method: name (default; also matches aliases), group, file, col
304
+ * pattern: glob with * and ?
305
+ * +x x plus the tables it references (parents), any depth; 2+x limits to 2 hops
306
+ * x+ x plus the tables referencing it (children); x+1 limits to 1 hop
307
+ */
308
+ function globRe(p) {
309
+ return new RegExp("^" + p.replace(/[.^$|()[\]{}\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".") + "$", "i");
310
+ }
311
+ function edges(model) {
312
+ var up = {}, down = {};
313
+ model.rels.forEach(function (r) {
314
+ var aMany = r.a.card === "many" || r.a.card === "zeroMany", bMany = r.b.card === "many" || r.b.card === "zeroMany";
315
+ var aIsChild = aMany || !bMany, child = aIsChild ? r.a.t : r.b.t, parent = aIsChild ? r.b.t : r.a.t;
316
+ if (child === parent) return;
317
+ (up[child] = up[child] || []).push(parent);
318
+ (down[parent] = down[parent] || []).push(child);
319
+ });
320
+ return { up: up, down: down };
321
+ }
322
+ function walk(start, adj, depth, into) {
323
+ var frontier = start, d = 0;
324
+ while (frontier.length && d < depth) {
325
+ var next = [];
326
+ frontier.forEach(function (id) {
327
+ (adj[id] || []).forEach(function (o) { if (!into[o]) { into[o] = true; next.push(o); } });
328
+ });
329
+ frontier = next;
330
+ d++;
331
+ }
332
+ }
333
+ function atomSet(model, atom, g) {
334
+ var m = /^(\d*\+)?(.*?)(\+\d*)?$/.exec(atom), up = m[1], body = m[2], down = m[3];
335
+ var method = "name", pat = body, i = body.indexOf(":");
336
+ if (i > 0) { method = body.slice(0, i).toLowerCase(); pat = body.slice(i + 1); }
337
+ var re = globRe(pat || "*"), out = {}, base = [];
338
+ model.tables.forEach(function (t) {
339
+ var ok;
340
+ if (method === "name") ok = re.test(t.name) || t.aliases.some(function (a) { return re.test(a); });
341
+ else if (method === "group") ok = re.test(t.group || "") || (t.group || "").toLowerCase().indexOf(pat.toLowerCase() + "/") === 0;
342
+ else if (method === "file") ok = re.test(t.file || "") || re.test((t.file || "").split("/").pop());
343
+ else if (method === "col" || method === "column") ok = t.cols.some(function (c) { return re.test(c.name); });
344
+ else if (method === "diff" || method === "state") {
345
+ var ds = t.diff && t.diff.state, want = pat.toLowerCase();
346
+ ok = !!ds && (want === "modified" || want === "*" || want === ds || (want === "new" && ds === "added"));
347
+ }
348
+ else throw new Error("unknown selector method '" + method + "' (use name, group, file, col, diff)");
349
+ if (ok) { out[t.id] = true; base.push(t.id); }
350
+ });
351
+ function hops(op, before) {
352
+ var n = before ? op.slice(0, -1) : op.slice(1);
353
+ return n ? parseInt(n, 10) : Infinity;
354
+ }
355
+ if (up) walk(base, g.up, hops(up, true), out);
356
+ if (down) walk(base, g.down, hops(down, false), out);
357
+ return out;
358
+ }
359
+ /* Returns the ids matching `expr`, in model order, or null when expr is blank (= everything). */
360
+ function select(model, expr) {
361
+ var tokens = String(expr || "").trim().split(/\s+/).filter(Boolean);
362
+ if (!tokens.length) return null;
363
+ var g = edges(model), inc = null, exc = {};
364
+ tokens.forEach(function (tok) {
365
+ var neg = tok.charAt(0) === "!";
366
+ if (neg) tok = tok.slice(1);
367
+ var parts = tok.split(",").filter(Boolean), set = null;
368
+ parts.forEach(function (p) {
369
+ var s = atomSet(model, p, g);
370
+ if (set === null) set = s;
371
+ else { var k = {}; Object.keys(set).forEach(function (id) { if (s[id]) k[id] = true; }); set = k; }
372
+ });
373
+ set = set || {};
374
+ if (neg) Object.keys(set).forEach(function (id) { exc[id] = true; });
375
+ else { inc = inc || {}; Object.keys(set).forEach(function (id) { inc[id] = true; }); }
376
+ });
377
+ return model.tables.filter(function (t) { return (inc === null || inc[t.id]) && !exc[t.id]; }).map(function (t) { return t.id; });
378
+ }
379
+
228
380
  root.qdbd = {
381
+ renderDrawio: renderDrawio,
382
+ select: select,
383
+ subset: subset,
229
384
  colors: C,
230
385
  geometry: geometry,
231
386
  renderTable: renderTable,
@@ -237,5 +392,7 @@
237
392
  esc: esc,
238
393
  };
239
394
  root.qdbdRenderSvg = renderSvg;
395
+ root.qdbdSelect = select;
396
+ root.qdbdRenderDrawio = renderDrawio;
240
397
  root.qdbdNeighbourhood = neighbourhood;
241
398
  })(typeof window !== "undefined" ? window : globalThis);
@@ -35,17 +35,70 @@ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
35
35
  .seg button.on { background: #fff; color: var(--blue); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
36
36
  .sep { width: 1px; height: 20px; background: #d5d9dd; margin: 0 4px; }
37
37
 
38
- /* search (top left) */
39
- .search { position: absolute; top: 14px; left: 16px; width: 260px; }
40
- .search input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit;
41
- background: #fff; outline: none; }
42
- .search input:focus { border-color: var(--blue); }
43
- .results { margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 300px;
44
- overflow: auto; display: none; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
45
- .results.open { display: block; }
46
- .results div { padding: 6px 10px; cursor: pointer; }
47
- .results div.sel, .results div:hover { background: #eef3fa; }
48
- .results small { color: var(--muted); margin-left: 6px; }
38
+ /* explorer (left): search + table tree grouped by file/folder */
39
+ .explorer { position: absolute; top: 14px; left: 16px; width: 270px; max-height: calc(100% - 60px); display: flex;
40
+ flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 8px;
41
+ box-shadow: 0 4px 14px rgba(0,0,0,.06); z-index: 3; }
42
+ .exhead { display: flex; align-items: center; gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); }
43
+ .explorer.collapsed .exhead { border-bottom: 0; }
44
+ .exhead button { border: 0; background: transparent; cursor: pointer; font-size: 15px; color: #666; padding: 4px 6px; border-radius: 4px; }
45
+ .exhead button:hover { background: #eef1f4; }
46
+ .exhead input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid transparent; border-radius: 5px; font: inherit;
47
+ background: #f4f5f6; outline: none; }
48
+ .exhead input:focus { border-color: var(--blue); background: #fff; }
49
+ .exfilter { padding: 6px 6px 4px; border-bottom: 1px solid var(--line); }
50
+ .explorer.collapsed .exfilter { display: none; }
51
+ .exfilter input { width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 5px; font: 12px Menlo, Consolas, monospace;
52
+ outline: none; }
53
+ .exfilter input:focus { border-color: var(--blue); }
54
+ .exfilter input.bad { border-color: #e57373; }
55
+ .fstat { font-size: 11px; color: var(--muted); padding: 3px 2px 0; min-height: 14px; }
56
+ .fstat.bad { color: #c0392b; }
57
+ .fstat a { color: var(--blue); cursor: pointer; margin-left: 6px; }
58
+ .tree { overflow: auto; padding: 4px 0 8px; }
59
+ .explorer.collapsed .tree { display: none; }
60
+ .gh { padding: 6px 12px 4px; font-size: 11px; font-weight: bold; color: var(--muted); text-transform: uppercase;
61
+ letter-spacing: .04em; cursor: pointer; user-select: none; display: flex; justify-content: space-between; }
62
+ .gh::before { content: "\25BE"; margin-right: 6px; }
63
+ .grp.shut .gh::before { content: "\25B8"; }
64
+ .gh span { font-weight: normal; }
65
+ .gh .gname { flex: 1; }
66
+ .grp.shut .gl { display: none; }
67
+ .ti { padding: 4px 12px 4px 26px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
68
+ .tree.flat .ti { padding-left: 14px; }
69
+ .ti small { color: var(--muted); margin-left: 6px; }
70
+ .ti:hover, .ti.sel { background: #eef3fa; }
71
+ .ti.cur { color: var(--blue); font-weight: bold; }
72
+ .tree .empty { padding: 8px 14px; color: var(--muted); }
73
+
74
+ /* details drawer (right) */
75
+ .details { position: absolute; top: 58px; right: 16px; bottom: 16px; width: 380px; background: #fff;
76
+ border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08); overflow: auto;
77
+ display: none; z-index: 3; padding: 16px 18px; }
78
+ .details.open { display: block; }
79
+ .has-details .minimap { right: 412px; }
80
+ .details .close { position: absolute; top: 8px; right: 10px; border: 0; background: transparent; font-size: 20px;
81
+ color: #888; cursor: pointer; }
82
+ .details h2 { margin: 0 24px 2px 0; font-size: 18px; color: var(--blue); word-break: break-word; }
83
+ .details .meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
84
+ .details .doc { white-space: pre-wrap; margin: 8px 0 12px; line-height: 1.45; }
85
+ .details h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }
86
+ .details table { width: 100%; border-collapse: collapse; font-size: 12px; }
87
+ .details td { padding: 5px 4px; border-top: 1px solid #eef0f2; vertical-align: top; }
88
+ .details td.cn { font-weight: 600; word-break: break-word; }
89
+ .details td.ct { color: #888; text-align: right; white-space: nowrap; }
90
+ .details .cd { color: #666; font-weight: normal; margin-top: 2px; white-space: pre-wrap; }
91
+ .details .tag { display: inline-block; font-size: 10px; padding: 0 5px; border-radius: 3px; background: #eef1f5;
92
+ color: #6b7a8c; margin: 0 3px 0 0; font-weight: normal; }
93
+ .details .tag.pk { background: #dfe8f6; color: var(--blue); }
94
+ .details .tag.fk { background: #ece6f7; color: #6a4fa3; }
95
+ .details ul { list-style: none; margin: 0; padding: 0; }
96
+ .details li { padding: 5px 0; border-top: 1px solid #eef0f2; }
97
+ .details a { color: var(--blue); text-decoration: none; cursor: pointer; }
98
+ .details a:hover { text-decoration: underline; }
99
+ .details .card { color: var(--muted); font-size: 11px; margin-left: 4px; }
100
+ .details .none { color: var(--muted); }
101
+ .details .hidden { color: var(--muted); }
49
102
 
50
103
  /* minimap (bottom right) */
51
104
  .minimap { position: absolute; right: 16px; bottom: 16px; width: 200px; height: 140px; background: rgba(255,255,255,.9);
@@ -53,6 +106,28 @@ html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
53
106
  .minimap svg { width: 100%; height: 100%; display: block; }
54
107
  .minimap .vpr { fill: rgba(43,87,151,.12); stroke: var(--blue); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
55
108
 
109
+ .toast { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: #23272b; color: #fff;
110
+ padding: 8px 14px; border-radius: 6px; font-size: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 6; }
111
+ .toast.open { opacity: 1; }
112
+
113
+ /* diff banner (build --diff-base) */
114
+ .diffbar { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); background: #fff; border: 1px solid var(--line);
115
+ border-radius: 8px; padding: 6px 12px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.06); display: none; z-index: 2;
116
+ white-space: nowrap; }
117
+ .diffbar.open { display: block; }
118
+ .diffbar b.add { color: #2e7d32; }
119
+ .diffbar b.chg { color: #d48806; }
120
+ .diffbar b.del { color: #c0392b; cursor: help; }
121
+ .diffbar a { color: var(--blue); cursor: pointer; margin-left: 10px; }
122
+ .details .chg { margin: 4px 0; }
123
+ .details .chg .add { color: #2e7d32; }
124
+ .details .chg .del { color: #c0392b; }
125
+ .details .chg .mod { color: #b07000; }
126
+ .details .state { display: inline-block; font-size: 10px; font-weight: bold; color: #fff; border-radius: 3px; padding: 1px 6px;
127
+ margin-left: 6px; vertical-align: middle; }
128
+ .details .state.added { background: #2e7d32; }
129
+ .details .state.changed { background: #d48806; }
130
+
56
131
  /* doc-comment tooltip */
57
132
  .tip { position: absolute; display: none; max-width: 340px; background: #23272b; color: #eee; border-radius: 6px;
58
133
  padding: 8px 10px; font-size: 12px; line-height: 1.45; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.25);