Files
relspecgo/pkg/readers/drawdb
Hein ed7130bba8 refactor(pkg): canonicalize base types and adjust length handling
* Update base types to keep explicit modifier forms
* Modify length handling for vector types in tests
2026-04-26 17:35:15 +02:00
..
2025-12-28 10:34:20 +02:00

DrawDB Reader

Reads DrawDB schema files and extracts database schema information.

Overview

The DrawDB Reader parses JSON files exported from DrawDB (a free online database design tool) and converts them into RelSpec's internal database model representation.

Features

  • Parses DrawDB JSON format
  • Extracts tables, fields, and relationships
  • Supports DrawDB-specific metadata
  • Preserves visual layout information

Usage

Basic Example

package main

import (
    "fmt"
    "git.warky.dev/wdevs/relspecgo/pkg/readers"
    "git.warky.dev/wdevs/relspecgo/pkg/readers/drawdb"
)

func main() {
    options := &readers.ReaderOptions{
        FilePath: "/path/to/diagram.json",
    }

    reader := drawdb.NewReader(options)
    db, err := reader.ReadDatabase()
    if err != nil {
        panic(err)
    }

    fmt.Printf("Found %d schemas\n", len(db.Schemas))
}

CLI Example

# Read DrawDB export and convert to JSON schema
relspec --input drawdb --in-file diagram.json --output json --out-file schema.json

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

Example DrawDB Export

DrawDB exports database designs as JSON files containing:

{
  "tables": [
    {
      "id": "1",
      "name": "users",
      "fields": [
        {
          "name": "id",
          "type": "BIGINT",
          "primary": true,
          "autoIncrement": true
        },
        {
          "name": "username",
          "type": "VARCHAR",
          "size": 50,
          "notNull": true,
          "unique": true
        }
      ]
    }
  ],
  "relationships": [
    {
      "source": "posts",
      "target": "users",
      "type": "many-to-one"
    }
  ]
}

Notes

  • DrawDB is a free online database designer at drawdb.vercel.app
  • Export format preserves visual design metadata
  • Useful for converting visual designs to code
  • Schema defaults to public