ui

package
v1.0.32 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package ui provides an interactive terminal user interface (TUI) for editing database schemas.

Overview

The ui package implements a full-featured terminal-based schema editor using tview, allowing users to visually create, modify, and manage database schemas without writing code or SQL.

Features

The schema editor supports:

  • Database management: Edit name, description, and properties
  • Schema management: Create, edit, delete schemas
  • Table management: Create, edit, delete tables
  • Column management: Add, modify, delete columns with full property support
  • Relationship management: Define and edit table relationships
  • Domain management: Organize tables into logical domains
  • Import & merge: Combine schemas from multiple sources
  • Save: Export to any supported format

Architecture

The package is organized into several components:

  • editor.go: Main editor and application lifecycle
  • *_screens.go: UI screens for each entity type
  • *_dataops.go: Business logic and data operations
  • dialogs.go: Reusable dialog components
  • load_save_screens.go: File I/O and format selection
  • main_menu.go: Primary navigation menu

Usage

editor := ui.NewSchemaEditor(database)
if err := editor.Run(); err != nil {
    log.Fatal(err)
}

Or with pre-configured load/save options:

editor := ui.NewSchemaEditorWithConfigs(database, loadConfig, saveConfig)
if err := editor.Run(); err != nil {
    log.Fatal(err)
}

Navigation

  • Arrow keys: Navigate between items
  • Enter: Select/edit item
  • Tab/Shift+Tab: Navigate between buttons
  • Escape: Go back/cancel
  • Letter shortcuts: Quick actions (e.g., 'n' for new, 'e' for edit, 'd' for delete)

Integration

The editor integrates with all readers and writers, supporting load/save operations for any format supported by RelSpec (DBML, PostgreSQL, GORM, Prisma, etc.).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadConfig

type LoadConfig struct {
	SourceType string
	FilePath   string
	ConnString string
}

LoadConfig holds the configuration for loading a database

type SaveConfig

type SaveConfig struct {
	TargetType string
	FilePath   string
	ConnString string
}

SaveConfig holds the configuration for saving a database

type SchemaEditor

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

SchemaEditor represents the interactive schema editor

func NewSchemaEditor

func NewSchemaEditor(db *models.Database) *SchemaEditor

NewSchemaEditor creates a new schema editor

func NewSchemaEditorWithConfigs

func NewSchemaEditorWithConfigs(db *models.Database, loadConfig *LoadConfig, saveConfig *SaveConfig) *SchemaEditor

NewSchemaEditorWithConfigs creates a new schema editor with load/save configurations

func (*SchemaEditor) CreateColumn

func (se *SchemaEditor) CreateColumn(schemaIndex, tableIndex int, name, dataType string, isPrimaryKey, isNotNull bool) *models.Column

CreateColumn creates a new column and adds it to a table

func (*SchemaEditor) CreateRelationship added in v1.0.31

func (se *SchemaEditor) CreateRelationship(schemaIndex, tableIndex int, rel *models.Relationship) *models.Relationship

CreateRelationship creates a new relationship and adds it to a table

func (*SchemaEditor) CreateSchema

func (se *SchemaEditor) CreateSchema(name, description string) *models.Schema

CreateSchema creates a new schema and adds it to the database

func (*SchemaEditor) CreateTable

func (se *SchemaEditor) CreateTable(schemaIndex int, name, description string) *models.Table

CreateTable creates a new table and adds it to a schema

func (*SchemaEditor) DeleteColumn

func (se *SchemaEditor) DeleteColumn(schemaIndex, tableIndex int, columnName string) bool

DeleteColumn removes a column from a table

func (*SchemaEditor) DeleteRelationship added in v1.0.31

func (se *SchemaEditor) DeleteRelationship(schemaIndex, tableIndex int, relName string) bool

DeleteRelationship removes a relationship from a table

func (*SchemaEditor) DeleteSchema

func (se *SchemaEditor) DeleteSchema(schemaIndex int) bool

DeleteSchema removes a schema from the database

func (*SchemaEditor) DeleteTable

func (se *SchemaEditor) DeleteTable(schemaIndex, tableIndex int) bool

DeleteTable removes a table from a schema

func (*SchemaEditor) GetAllColumns

func (se *SchemaEditor) GetAllColumns(schemaIndex, tableIndex int) map[string]*models.Column

GetAllColumns returns all columns in a table

func (*SchemaEditor) GetAllSchemas

func (se *SchemaEditor) GetAllSchemas() []*models.Schema

GetAllSchemas returns all schemas

func (*SchemaEditor) GetAllTables

func (se *SchemaEditor) GetAllTables() []*models.Table

GetAllTables returns all tables across all schemas

func (*SchemaEditor) GetColumn

func (se *SchemaEditor) GetColumn(schemaIndex, tableIndex int, columnName string) *models.Column

GetColumn returns a column by name

func (*SchemaEditor) GetDatabase

func (se *SchemaEditor) GetDatabase() *models.Database

GetDatabase returns the current database

func (*SchemaEditor) GetRelationship added in v1.0.31

func (se *SchemaEditor) GetRelationship(schemaIndex, tableIndex int, relName string) *models.Relationship

GetRelationship returns a relationship by name

func (*SchemaEditor) GetRelationshipNames added in v1.0.31

func (se *SchemaEditor) GetRelationshipNames(schemaIndex, tableIndex int) []string

GetRelationshipNames returns all relationship names for a table

func (*SchemaEditor) GetSchema

func (se *SchemaEditor) GetSchema(schemaIndex int) *models.Schema

GetSchema returns a schema by index

func (*SchemaEditor) GetTable

func (se *SchemaEditor) GetTable(schemaIndex, tableIndex int) *models.Table

GetTable returns a table by schema and table index

func (*SchemaEditor) GetTablesInSchema

func (se *SchemaEditor) GetTablesInSchema(schemaIndex int) []*models.Table

GetTablesInSchema returns all tables in a specific schema

func (*SchemaEditor) Run

func (se *SchemaEditor) Run() error

Run starts the interactive editor

func (*SchemaEditor) UpdateColumn

func (se *SchemaEditor) UpdateColumn(schemaIndex, tableIndex int, oldName, newName, dataType string, isPrimaryKey, isNotNull bool, defaultValue interface{}, description string) bool

UpdateColumn updates an existing column's properties

func (*SchemaEditor) UpdateRelationship added in v1.0.31

func (se *SchemaEditor) UpdateRelationship(schemaIndex, tableIndex int, oldName string, rel *models.Relationship) bool

UpdateRelationship updates an existing relationship

func (*SchemaEditor) UpdateSchema

func (se *SchemaEditor) UpdateSchema(schemaIndex int, name, owner, description string)

UpdateSchema updates an existing schema's properties

func (*SchemaEditor) UpdateTable

func (se *SchemaEditor) UpdateTable(schemaIndex, tableIndex int, name, description string)

UpdateTable updates an existing table's properties

Jump to

Keyboard shortcuts

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