Guide
This guide covers how to install erdn-lang, use the CLI, and integrate it into your workflow.
Prerequisites
You need Go 1.21 or later installed on your system.
Installation
Install via go install
The fastest way to get started:
go install github.com/headercat/erdn-lang/cmd/erdn@latestThis places the erdn binary in your $GOPATH/bin (or $HOME/go/bin by default). Make sure this directory is in your PATH.
Build from source
git clone https://github.com/headercat/erdn-lang.git
cd erdn-lang
go build -o erdn ./cmd/erdnYou can move the resulting erdn binary anywhere on your PATH.
Usage
erdn render <schema.erdn> [--out <file.svg>]
erdn validate <schema.erdn>
erdn sql <schema.erdn> [--dbms <mysql|postgresql|mssql|oracle|sqlite>] [--out <file.sql>]render
Parses and validates the schema, then writes an SVG diagram.
# Output defaults to <schema>.svg
erdn render schema.erdn
# Specify a custom output path
erdn render schema.erdn --out diagrams/schema.svgThe command:
- Reads and lexes the
.erdnsource file. - Parses it into an internal AST.
- Runs semantic validation (catches unknown tables, duplicate columns, etc.).
- Renders the validated AST to a self-contained SVG file.
validate
Checks the schema for parse and semantic errors without producing any output file. Exits with a non-zero status code if errors are found.
erdn validate schema.erdn
# OKUse validate in CI pipelines to catch schema errors early.
sql
Generates SQL DDL from the schema — CREATE TABLE statements, indexes, and foreign key constraints. Use --dbms to target a specific database engine (default: mysql).
| DBMS | Flag value |
|---|---|
| MySQL | mysql |
| PostgreSQL | postgresql |
| Microsoft SQL Server | mssql |
| Oracle Database | oracle |
| SQLite | sqlite |
# Output defaults to <schema>.sql (MySQL)
erdn sql schema.erdn
# Target PostgreSQL
erdn sql schema.erdn --dbms postgresql
# Specify a custom output path
erdn sql schema.erdn --dbms mssql --out migrations/001_init.sqlThe generated SQL includes:
CREATE TABLEstatements with DBMS-appropriate column types and constraints.PRIMARY KEYconstraints.- Auto-increment syntax suited to the target DBMS (
AUTO_INCREMENT,IDENTITY(1,1),GENERATED ALWAYS AS IDENTITY, orAUTOINCREMENT). CREATE INDEXstatements for columns markedindexed.- Foreign key constraints derived from
linkdeclarations — asALTER TABLE … ADD CONSTRAINT … FOREIGN KEYfor most databases, or as inlineFOREIGN KEYtable constraints for SQLite.
Writing Your First Schema
Create a file called blog.erdn:
# A simple blog schema
table authors (
# Unique identifier for each author
id bigint primary-key auto-increment
username varchar(64) not-null indexed
email varchar(255) not-null indexed
bio text nullable
)
table posts (
# One row per published article
id bigint primary-key auto-increment
author_id bigint not-null indexed
title varchar(512) not-null
body text not-null
# draft, published, archived
status varchar(32) not-null default("draft")
created_at timestamp not-null default(NOW())
)
# An author can write many posts
link one authors.id to many posts.author_idRender it:
erdn render blog.erdn
# rendered blog.svgWorkflow Tips
- Version control — commit
.erdnfiles alongside your application code. Diffs are human-readable. - CI integration — add
erdn validateto your CI pipeline to prevent broken schemas from being merged. - Automated rendering — use
erdn renderin CI to produce SVG artifacts for every commit. - Playground — use the online Playground to experiment without installing anything.
Next Steps
- Read the full Syntax Specification for every language construct.
- Try the live Playground in your browser.
- Explore ready-to-use Recipes for GitHub Actions and other integrations.