- Implement functionality to create, update, delete, and view relationships between tables. - Introduce new UI screens for managing relationships, including forms for adding and editing relationships. - Enhance table editor with navigation to relationship management. - Ensure relationships are displayed in a structured table format for better usability.
5.0 KiB
5.0 KiB
RelSpec API Documentation (godoc)
This document explains how to access and use the RelSpec API documentation.
Viewing Documentation Locally
Using go doc Command Line
View package documentation:
# Main package overview
go doc
# Specific package
go doc ./pkg/models
go doc ./pkg/readers
go doc ./pkg/writers
go doc ./pkg/ui
# Specific type or function
go doc ./pkg/models Database
go doc ./pkg/readers Reader
go doc ./pkg/writers Writer
View all documentation for a package:
go doc -all ./pkg/models
go doc -all ./pkg/readers
go doc -all ./pkg/writers
Using godoc Web Server
Quick Start (Recommended):
make godoc
This will automatically install godoc if needed and start the server on port 6060.
Manual Installation:
go install golang.org/x/tools/cmd/godoc@latest
godoc -http=:6060
Then open your browser to:
http://localhost:6060/pkg/git.warky.dev/wdevs/relspecgo/
Package Documentation
Core Packages
pkg/models- Core data structures (Database, Schema, Table, Column, etc.)pkg/readers- Input format readers (dbml, pgsql, gorm, prisma, etc.)pkg/writers- Output format writers (dbml, pgsql, gorm, prisma, etc.)
Utility Packages
pkg/diff- Schema comparison and difference detectionpkg/merge- Schema merging utilitiespkg/transform- Validation and normalizationpkg/ui- Interactive terminal UI for schema editing
Support Packages
pkg/pgsql- PostgreSQL-specific utilitiespkg/inspector- Database introspection capabilitiespkg/reflectutil- Reflection utilities for Go code analysispkg/commontypes- Shared type definitions
Reader Implementations
Each reader is in its own subpackage under pkg/readers/:
pkg/readers/dbml- DBML format readerpkg/readers/dctx- DCTX format readerpkg/readers/drawdb- DrawDB JSON readerpkg/readers/graphql- GraphQL schema readerpkg/readers/json- JSON schema readerpkg/readers/yaml- YAML schema readerpkg/readers/gorm- Go GORM models readerpkg/readers/bun- Go Bun models readerpkg/readers/drizzle- TypeScript Drizzle ORM readerpkg/readers/prisma- Prisma schema readerpkg/readers/typeorm- TypeScript TypeORM readerpkg/readers/pgsql- PostgreSQL database readerpkg/readers/sqlite- SQLite database reader
Writer Implementations
Each writer is in its own subpackage under pkg/writers/:
pkg/writers/dbml- DBML format writerpkg/writers/dctx- DCTX format writerpkg/writers/drawdb- DrawDB JSON writerpkg/writers/graphql- GraphQL schema writerpkg/writers/json- JSON schema writerpkg/writers/yaml- YAML schema writerpkg/writers/gorm- Go GORM models writerpkg/writers/bun- Go Bun models writerpkg/writers/drizzle- TypeScript Drizzle ORM writerpkg/writers/prisma- Prisma schema writerpkg/writers/typeorm- TypeScript TypeORM writerpkg/writers/pgsql- PostgreSQL SQL writerpkg/writers/sqlite- SQLite SQL writer
Usage Examples
Reading a Schema
import (
"git.warky.dev/wdevs/relspecgo/pkg/readers"
"git.warky.dev/wdevs/relspecgo/pkg/readers/dbml"
)
reader := dbml.NewReader(&readers.ReaderOptions{
FilePath: "schema.dbml",
})
db, err := reader.ReadDatabase()
Writing a Schema
import (
"git.warky.dev/wdevs/relspecgo/pkg/writers"
"git.warky.dev/wdevs/relspecgo/pkg/writers/gorm"
)
writer := gorm.NewWriter(&writers.WriterOptions{
OutputPath: "./models",
PackageName: "models",
})
err := writer.WriteDatabase(db)
Comparing Schemas
import "git.warky.dev/wdevs/relspecgo/pkg/diff"
result := diff.CompareDatabases(sourceDB, targetDB)
err := diff.FormatDiff(result, diff.OutputFormatText, os.Stdout)
Merging Schemas
import "git.warky.dev/wdevs/relspecgo/pkg/merge"
result := merge.MergeDatabases(targetDB, sourceDB, nil)
fmt.Printf("Added %d tables\n", result.TablesAdded)
Documentation Standards
All public APIs follow Go documentation conventions:
- Package documentation in
doc.gofiles - Type, function, and method comments start with the item name
- Examples where applicable
- Clear description of parameters and return values
- Usage notes and caveats where relevant
Generating Documentation
To regenerate documentation after code changes:
# Verify documentation builds correctly
go doc -all ./pkg/... > /dev/null
# Check for undocumented exports
go vet ./...
Contributing Documentation
When adding new packages or exported items:
- Add package documentation in a
doc.gofile - Document all exported types, functions, and methods
- Include usage examples for complex APIs
- Follow Go documentation style guide
- Verify with
go docbefore committing