A single table in detail — every column, its type, and the keys and references it participates in.The code#
import { ModelDiagram } from 'ts-prorm-orm';
const svg = new ModelDiagram({
name: 'Post',
tableName: 'posts',
comment: 'Articles written by a user',
fields: {
id: { type: 'INTEGER', primaryKey: true, autoIncrement: true },
title: { type: 'VARCHAR(200)', allowNull: false },
body: { type: 'TEXT' },
authorId: { type: 'INTEGER', allowNull: false,
references: { model: 'User', key: 'id' } },
},
}).generate();
What it produces#
Generated by running the snippet above — this is the generator's real output,
rebuilt by scripts/build-diagram-examples.mjs, not a picture of it.Primary keys, unique constraints, nullability and foreign keys are all marked, so the diagram carries the same information as the CREATE TABLE.Saving it#
generate() returns the SVG as a string; save(path) writes it straight to
disk.diagram.save('docs/schema.svg');
Models — the definitions these are drawn from Modified at 2026-10-04 00:40:16