erd

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package erd provides schema introspection and ERD rendering for Postgres and MySQL databases. It uses information_schema to remain engine-agnostic and avoids any engine-specific system catalogue queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderDBML

func RenderDBML(s *Schema, w io.Writer) error

RenderDBML writes a DBML representation to w. DBML (Database Markup Language) is the format used by dbdiagram.io.

func RenderMermaid

func RenderMermaid(s *Schema, w io.Writer) error

RenderMermaid writes a Mermaid erDiagram block to w.

Types

type Column

type Column struct {
	Name     string
	DataType string
	Nullable bool
	IsPK     bool
}

Column describes a single column in a table.

type ForeignKey

type ForeignKey struct {
	FromTable  string
	FromColumn string
	ToTable    string
	ToColumn   string
}

ForeignKey describes a referential constraint between two tables.

type Schema

type Schema struct {
	Tables      []Table
	ForeignKeys []ForeignKey
}

Schema is the result of introspecting a database.

func Introspect

func Introspect(ctx context.Context, db *sql.DB, engineName, database string) (*Schema, error)

Introspect queries information_schema for tables, columns, primary keys, and foreign keys. engineName must be "postgres" or "mysql". database is only used for MySQL (Postgres always targets the "public" schema).

type Table

type Table struct {
	Name    string
	Columns []Column
}

Table describes a database table and its columns.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL