b55737ab4c3fc2734f9b9f879f7aaddaccb05bf9
RelSpec
Database Relations Specification Tool for Go
RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs.
Overview
RelSpec provides bidirectional conversion and comparison between various database specification formats, allowing you to:
- Inspect live databases and extract their structure
- Convert between different ORM models (GORM, Bun , etc.)
- Transform legacy schema definitions (Clarion DCTX, XML, JSON, etc.)
- Generate standardized specification files (JSON, YAML, etc.)
Features
Readers (Input Formats)
RelSpec can read database schemas from multiple sources:
ORM Models
- GORM - Go GORM model definitions
- Bun - Go Bun model definitions
- Drizzle - TypeScript Drizzle ORM schemas
- Prisma - Prisma schema language
- TypeORM - TypeScript TypeORM entities
Database Inspection
- PostgreSQL - Direct PostgreSQL database introspection
Schema Formats
- DBML - Database Markup Language (dbdiagram.io)
- DCTX - Clarion database dictionary format
- DrawDB - DrawDB JSON format
- GraphQL - GraphQL Schema Definition Language (SDL)
- JSON - RelSpec canonical JSON format
- YAML - RelSpec canonical YAML format
Writers (Output Formats)
RelSpec can write database schemas to multiple formats:
ORM Models
- GORM - Generate GORM-compatible Go structs
- Bun - Generate Bun-compatible Go structs
- Drizzle - Generate Drizzle ORM TypeScript schemas
- Prisma - Generate Prisma schema files
- TypeORM - Generate TypeORM TypeScript entities
Database DDL
- PostgreSQL - PostgreSQL DDL (CREATE TABLE, etc.)
Schema Formats
- DBML - Database Markup Language
- DCTX - Clarion database dictionary format
- DrawDB - DrawDB JSON format
- GraphQL - GraphQL Schema Definition Language (SDL)
- JSON - RelSpec canonical JSON format
- YAML - RelSpec canonical YAML format
Use of AI
Installation
go get github.com/wdevs/relspecgo
go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
Usage
# Inspect database and generate GORM models
relspec --input db --conn "postgres://..." --output gorm --out-file models.go
# Convert GORM models to Bun
relspec --input gorm --in-file existing.go --output bun --out-file bun_models.go
# Export database schema to JSON
relspec --input db --conn "mysql://..." --output json --out-file schema.json
# Convert Clarion DCTX to YAML
relspec --input dctx --in-file legacy.dctx --output yaml --out-file schema.yaml
Project Structure
relspecgo/
├── cmd/ # CLI application
├── pkg/
│ ├── readers/ # Input format readers
│ ├── writers/ # Output format writers
│ ├── models/ # Internal data models
│ └── transform/ # Transformation logic
├── examples/ # Usage examples
└── tests/ # Test files
Todo
Development
Prerequisites
- Go 1.21 or higher
- Access to test databases (optional)
Building
go build -o relspec ./cmd/relspec
Testing
go test ./...
License
Apache License 2.0 - See LICENSE for details.
Copyright 2025 Warky Devs
Contributing
Contributions welcome. Please open an issue or submit a pull request.
Description
