Skip to content

Commit 5cf9a31

Browse files
committed
Allow displaying FN actions
1 parent 68c3b9d commit 5cf9a31

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function App() {
8585
return;
8686
}
8787
};
88-
const dot = layout.getDot();
88+
const dot = layout.getDot({ displayActions: isSemanticallyTruthy(searchParams.get("actions"), false) });
8989
if (isSemanticallyTruthy(searchParams.get("debug"))) {
9090
// eslint-disable-next-line no-console
9191
console.log(dot);

src/utils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class SQLiteLayout {
392392
return { dot: parts.join("\n"), id: tableId, mappings, extraMappings };
393393
}
394394

395-
private getDotForeignKey(foreignKey: ForeignKey, tables: { [name: string]: DotTable }): string {
395+
private getDotForeignKey(foreignKey: ForeignKey, tables: { [name: string]: DotTable }, displayActions: boolean): string {
396396
const fromTable = tables[foreignKey.from.name];
397397
const toTable = tables[foreignKey.to.name];
398398

@@ -412,11 +412,15 @@ export class SQLiteLayout {
412412

413413
const [tailLabel, headLabel] = foreignKeyTypeToTuple(this.getForeignKeyType(foreignKey));
414414

415-
// label=<<I>{${foreignKey.onUpdate}, ${foreignKey.onDelete}}</I>>
416-
return `"${foreignKey.from.name}":${fromColumnId} -> "${foreignKey.to.name}":${toColumnId} [dir=forward, penwidth=4, color="#29235c", headlabel="${headLabel}", taillabel="${tailLabel}" labeldistance=3.5, labelfontsize=52, arrowhead=open, arrowsize=2];`;
415+
const label = displayActions ? `label=<<I>${foreignKey.onUpdate}, ${foreignKey.onDelete}</I>>, fontsize=42, ` : "";
416+
return `"${foreignKey.from.name}":${fromColumnId} -> "${foreignKey.to.name}":${toColumnId} [dir=forward, penwidth=4, color="#29235c", ${label}headlabel="${headLabel}", taillabel="${tailLabel}" labeldistance=3.5, labelfontsize=52, arrowhead=open, arrowsize=2];`;
417417
}
418418

419-
public getDot(): string {
419+
public getDot(
420+
options?: {
421+
displayActions?: boolean;
422+
}
423+
): string {
420424
this.dotIdCounter = 1;
421425
const parts: string[] = [];
422426
parts.push("digraph SQLiteLayout {");
@@ -430,7 +434,7 @@ export class SQLiteLayout {
430434
}, {} as { [name: string]: DotTable });
431435
parts.push(...Object.values(tables).map((table) => table.dot));
432436

433-
const foreignKeys = this.getForeignKeys().map((foreignKey) => this.getDotForeignKey(foreignKey, tables)).filter((fk) => fk.length > 0);
437+
const foreignKeys = this.getForeignKeys().map((foreignKey) => this.getDotForeignKey(foreignKey, tables, options?.displayActions || false)).filter((fk) => fk.length > 0);
434438
parts.push(...foreignKeys);
435439
parts.push("}");
436440

0 commit comments

Comments
 (0)