pgdesign v0.26.0 /internal/generate
On this page

Package generate transforms a resolved model.Schema into PostgreSQL DDL output including tables, views, materialized views, functions, and triggers.

#internal/generate

#internal/generate

Package generate transforms a resolved model.Schema into PostgreSQL DDL output including tables, views, materialized views, functions, and triggers.

#TableStats

Go go
type TableStats struct

TableStats is caller-provided live statistics for one table, keyed into D2Options.Stats by model.TableKey(schema, name). The generate package never fetches these itself — it stays DB-free (roadmap L5: no DB import in generate). serve and the CLI fetch them from a live database and inject them here so heat-map/live annotations render without generate ever touching pgx.

#D2Options

Go go
type D2Options struct

D2Options controls D2 diagram enrichment, filtering, cardinality, heat maps, layout, and rendering. This is deliberately plain presentation configuration outside the algebra: only its inputs (the canonical model, the FK graph, the imported reference shapes) are law-governed.

Construct with DefaultD2Options and override individual fields; the zero value disables every enrichment layer and is NOT the intended default.

#Options

Go go
type Options struct

Options controls the DDL output behavior.

#GenerateD2

Go go
func GenerateD2(schema *model.Schema, reg *semtype.Registry, opts D2Options) string

GenerateD2 produces D2 diagram language text from a resolved schema. Each table is rendered as a sql_table shape with columns listed, and FK relationships appear as labeled edges with the ON DELETE action. When reg is non-nil, state machine types are rendered as state diagrams. opts controls layout direction, enrichment layers, filtering, cardinality, and heat maps; pass DefaultD2Options for the intended defaults.

#RenderSVG

Go go
func RenderSVG(d2Source string, opts D2Options) ([]byte, error)

RenderSVG compiles D2 source text and renders it to SVG bytes. opts selects the layout engine (dagre or elk — TALA is not in the OSS library) and the SVG theme id; direction is a source-level concern already emitted by GenerateD2, so it is not re-applied here.

#DefaultD2Options

Go go
func DefaultD2Options() D2Options

DefaultD2Options returns the intended defaults: dagre layout, downward direction, every enrichment layer and cardinality enabled, no filtering, and no heat map.

#Generate

Go go
func Generate(schema *model.Schema, opts Options) (string, []diagnostic.Diagnostic, error)

Generate produces DDL output for the given schema according to opts.

#D2Options.Validate

Go go
func (o D2Options) Validate() error

Validate reports a hard error for any out-of-range option. TALA is rejected with a specific message because it is a common request that the OSS library cannot satisfy.

Search