drawdb

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

DrawDB Writer

Generates DrawDB-compatible JSON files from database schema information.

Overview

The DrawDB Writer converts RelSpec's internal database model representation into JSON format compatible with DrawDB, a free online database design tool.

Features

  • Generates DrawDB JSON format
  • Creates table and field definitions
  • Defines relationships
  • Includes visual layout information
  • Preserves constraints and indexes

Usage

Basic Example
package main

import (
    "git.warky.dev/wdevs/relspecgo/pkg/models"
    "git.warky.dev/wdevs/relspecgo/pkg/writers"
    "git.warky.dev/wdevs/relspecgo/pkg/writers/drawdb"
)

func main() {
    options := &writers.WriterOptions{
        OutputPath: "diagram.json",
    }

    writer := drawdb.NewWriter(options)
    err := writer.WriteDatabase(db)
    if err != nil {
        panic(err)
    }
}
CLI Examples
# Generate DrawDB diagram from PostgreSQL database
relspec --input pgsql \
  --conn "postgres://localhost/mydb" \
  --output drawdb \
  --out-file diagram.json

# Convert GORM models to DrawDB for visualization
relspec --input gorm --in-file models.go --output drawdb --out-file design.json

# Convert JSON schema to DrawDB
relspec --input json --in-file schema.json --output drawdb --out-file diagram.json

Generated JSON Example

{
  "version": "1.0",
  "database": "PostgreSQL",
  "tables": [
    {
      "id": "1",
      "name": "users",
      "x": 100,
      "y": 100,
      "fields": [
        {
          "id": "1",
          "name": "id",
          "type": "BIGINT",
          "primary": true,
          "autoIncrement": true,
          "notNull": true
        },
        {
          "id": "2",
          "name": "username",
          "type": "VARCHAR",
          "size": 50,
          "notNull": true,
          "unique": true
        },
        {
          "id": "3",
          "name": "email",
          "type": "VARCHAR",
          "size": 100,
          "notNull": true
        }
      ],
      "indexes": [
        {
          "name": "idx_users_email",
          "fields": ["email"]
        }
      ]
    },
    {
      "id": "2",
      "name": "posts",
      "x": 400,
      "y": 100,
      "fields": [
        {
          "id": "1",
          "name": "id",
          "type": "BIGINT",
          "primary": true
        },
        {
          "id": "2",
          "name": "user_id",
          "type": "BIGINT",
          "notNull": true
        },
        {
          "id": "3",
          "name": "title",
          "type": "VARCHAR",
          "size": 200,
          "notNull": true
        }
      ]
    }
  ],
  "relationships": [
    {
      "id": "1",
      "source": "2",
      "target": "1",
      "sourceField": "user_id",
      "targetField": "id",
      "type": "many-to-one",
      "onDelete": "CASCADE"
    }
  ]
}

DrawDB Features

Table Properties
  • id - Unique table identifier
  • name - Table name
  • x, y - Position in diagram
  • fields - Array of field definitions
  • indexes - Array of index definitions
Field Properties
  • id - Unique field identifier
  • name - Field name
  • type - Data type (BIGINT, VARCHAR, etc.)
  • size - Length for string types
  • primary - Primary key flag
  • notNull - NOT NULL constraint
  • unique - Unique constraint
  • autoIncrement - Auto-increment flag
  • default - Default value
Relationship Properties
  • id - Unique relationship identifier
  • source - Source table ID
  • target - Target table ID
  • sourceField - Foreign key field
  • targetField - Referenced field
  • type - Relationship type (one-to-one, one-to-many, many-to-one)
  • onDelete - Delete action
  • onUpdate - Update action

Notes

  • DrawDB is available at drawdb.vercel.app
  • Generated files can be imported for visual editing
  • Visual positions (x, y) are auto-generated
  • Ideal for creating ERD diagrams
  • Supports modern database features
  • Free and open-source tool

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DrawDBArea

type DrawDBArea struct {
	ID     int    `json:"id" yaml:"id" xml:"id"`
	Name   string `json:"name" yaml:"name" xml:"name"`
	Color  string `json:"color" yaml:"color" xml:"color"`
	X      int    `json:"x" yaml:"x" xml:"x"`
	Y      int    `json:"y" yaml:"y" xml:"y"`
	Width  int    `json:"width" yaml:"width" xml:"width"`
	Height int    `json:"height" yaml:"height" xml:"height"`
}

DrawDBArea represents a subject area/grouping in DrawDB format

type DrawDBField

type DrawDBField struct {
	ID        int    `json:"id" yaml:"id" xml:"id"`
	Name      string `json:"name" yaml:"name" xml:"name"`
	Type      string `json:"type" yaml:"type" xml:"type"`
	Default   string `json:"default,omitempty" yaml:"default,omitempty" xml:"default,omitempty"`
	Check     string `json:"check,omitempty" yaml:"check,omitempty" xml:"check,omitempty"`
	Primary   bool   `json:"primary" yaml:"primary" xml:"primary"`
	Unique    bool   `json:"unique" yaml:"unique" xml:"unique"`
	NotNull   bool   `json:"notNull" yaml:"notNull" xml:"notNull"`
	Increment bool   `json:"increment" yaml:"increment" xml:"increment"`
	Comment   string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
}

DrawDBField represents a column/field in DrawDB format

type DrawDBIndex

type DrawDBIndex struct {
	ID     int    `json:"id" yaml:"id" xml:"id"`
	Name   string `json:"name" yaml:"name" xml:"name"`
	Unique bool   `json:"unique" yaml:"unique" xml:"unique"`
	Fields []int  `json:"fields" yaml:"fields" xml:"fields"` // Field IDs
}

DrawDBIndex represents an index in DrawDB format

type DrawDBNote

type DrawDBNote struct {
	ID      int    `json:"id" yaml:"id" xml:"id"`
	Content string `json:"content" yaml:"content" xml:"content"`
	Color   string `json:"color" yaml:"color" xml:"color"`
	X       int    `json:"x" yaml:"x" xml:"x"`
	Y       int    `json:"y" yaml:"y" xml:"y"`
}

DrawDBNote represents a note in DrawDB format

type DrawDBRelationship

type DrawDBRelationship struct {
	ID               int    `json:"id" yaml:"id" xml:"id"`
	Name             string `json:"name" yaml:"name" xml:"name"`
	StartTableID     int    `json:"startTableId" yaml:"startTableId" xml:"startTableId"`
	EndTableID       int    `json:"endTableId" yaml:"endTableId" xml:"endTableId"`
	StartFieldID     int    `json:"startFieldId" yaml:"startFieldId" xml:"startFieldId"`
	EndFieldID       int    `json:"endFieldId" yaml:"endFieldId" xml:"endFieldId"`
	Cardinality      string `json:"cardinality" yaml:"cardinality" xml:"cardinality"` // "One to one", "One to many", "Many to one"
	UpdateConstraint string `json:"updateConstraint,omitempty" yaml:"updateConstraint,omitempty" xml:"updateConstraint,omitempty"`
	DeleteConstraint string `json:"deleteConstraint,omitempty" yaml:"deleteConstraint,omitempty" xml:"deleteConstraint,omitempty"`
}

DrawDBRelationship represents a relationship in DrawDB format

type DrawDBSchema

type DrawDBSchema struct {
	Tables        []*DrawDBTable        `json:"tables" yaml:"tables" xml:"tables"`
	Relationships []*DrawDBRelationship `json:"relationships" yaml:"relationships" xml:"relationships"`
	Notes         []*DrawDBNote         `json:"notes,omitempty" yaml:"notes,omitempty" xml:"notes,omitempty"`
	SubjectAreas  []*DrawDBArea         `json:"subjectAreas,omitempty" yaml:"subjectAreas,omitempty" xml:"subjectAreas,omitempty"`
}

DrawDBSchema represents the complete DrawDB JSON structure

type DrawDBTable

type DrawDBTable struct {
	ID      int            `json:"id" yaml:"id" xml:"id"`
	Name    string         `json:"name" yaml:"name" xml:"name"`
	Schema  string         `json:"schema,omitempty" yaml:"schema,omitempty" xml:"schema,omitempty"`
	Comment string         `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
	Color   string         `json:"color" yaml:"color" xml:"color"`
	X       int            `json:"x" yaml:"x" xml:"x"`
	Y       int            `json:"y" yaml:"y" xml:"y"`
	Fields  []*DrawDBField `json:"fields" yaml:"fields" xml:"fields"`
	Indexes []*DrawDBIndex `json:"indexes,omitempty" yaml:"indexes,omitempty" xml:"indexes,omitempty"`
}

DrawDBTable represents a table in DrawDB format

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements the writers.Writer interface for DrawDB JSON format

func NewWriter

func NewWriter(options *writers.WriterOptions) *Writer

NewWriter creates a new DrawDB writer with the given options

func (*Writer) WriteDatabase

func (w *Writer) WriteDatabase(db *models.Database) error

WriteDatabase writes a Database model to DrawDB JSON format

func (*Writer) WriteSchema

func (w *Writer) WriteSchema(schema *models.Schema) error

WriteSchema writes a Schema model to DrawDB JSON format

func (*Writer) WriteTable

func (w *Writer) WriteTable(table *models.Table) error

WriteTable writes a Table model to DrawDB JSON format

Jump to

Keyboard shortcuts

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