ui

package
v1.0.87 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 45 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

func BuildConnString added in v1.0.86

func BuildConnString(f ConnFields, mask bool) string

BuildConnString renders the fields as a connection string. With mask set, a non-empty password is replaced by asterisks (for previews).

func ExpandHome added in v1.0.86

func ExpandHome(p string) string

ExpandHome replaces a leading ~ with the user's home directory.

func FormatExtensions added in v1.0.86

func FormatExtensions(format string) []string

FormatExtensions returns the extensions for a format, or nil (no filter) if unknown.

func IsDirectoryFormat added in v1.0.86

func IsDirectoryFormat(format string) bool

IsDirectoryFormat reports whether a format can be loaded from or saved to a directory.

func MatchesExtension added in v1.0.86

func MatchesExtension(name string, exts []string) bool

MatchesExtension reports whether name has one of exts (case-insensitive). An empty extension list matches everything.

func ResolveStart added in v1.0.86

func ResolveStart(input string) (dir, name string)

ResolveStart works out where the browser should open for the current input value. It returns the directory to show and, if the input named a file, its base name. Falls back to the working directory.

func SSLModes added in v1.0.86

func SSLModes(kind ConnKind) []string

SSLModes returns the valid SSL/encryption options for a kind.

func TestConnection added in v1.0.86

func TestConnection(f ConnFields) error

TestConnection opens and pings the database described by f. Any occurrence of the password in the returned error is masked.

Types

type ConnFields added in v1.0.86

type ConnFields struct {
	Kind     ConnKind
	Host     string
	Port     string
	Database string
	User     string
	Password string
	SSLMode  string
	FilePath string // SQLite only

	// Extra keeps query parameters the builder has no field for, so that
	// parsing and rebuilding an existing string does not drop them.
	Extra url.Values
}

ConnFields holds the editable parts of a connection string.

func DefaultConnFields added in v1.0.86

func DefaultConnFields(kind ConnKind) ConnFields

DefaultConnFields returns sensible defaults for the given kind.

func ParseConnString added in v1.0.86

func ParseConnString(s string, hint ConnKind) (ConnFields, error)

ParseConnString splits a connection string into fields. An empty string yields the defaults for hint. Missing ports fall back to the kind default.

type ConnKind added in v1.0.86

type ConnKind string

ConnKind identifies the database type a connection string targets.

const (
	ConnPostgres ConnKind = "postgres"
	ConnMSSQL    ConnKind = "mssql"
	ConnSQLite   ConnKind = "sqlite"
)

func DetectConnKind added in v1.0.86

func DetectConnKind(s string) ConnKind

DetectConnKind guesses the kind from a connection string's scheme. Anything that is not a recognised URL is treated as a SQLite file path.

type FileBrowserConfig added in v1.0.86

type FileBrowserConfig struct {
	Mode       FileBrowserMode
	StartPath  string   // current value of the input; may be empty
	Extensions []string // empty = show all files
	AllowDir   bool     // a directory is a valid result (directory-based formats)
	ReturnPage string   // page to switch back to when the dialog closes
	OnSelect   func(path string)
}

FileBrowserConfig configures the file browser dialog.

type FileBrowserMode added in v1.0.86

type FileBrowserMode int

FileBrowserMode selects between picking an existing path and choosing a save target.

const (
	FileBrowserLoad FileBrowserMode = iota
	FileBrowserSave
)

type FileEntry added in v1.0.86

type FileEntry struct {
	Name  string
	IsDir bool
}

FileEntry is a single row in the file browser.

func ListDir added in v1.0.86

func ListDir(dir string, exts []string, showHidden bool) ([]FileEntry, error)

ListDir returns the entries of dir: directories first, then files that match exts, each group sorted case-insensitively. Hidden (dot) entries are skipped unless showHidden is set.

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) AssignTableToDomain added in v1.0.86

func (se *SchemaEditor) AssignTableToDomain(domainIndex int, schemaName, tableName string) error

AssignTableToDomain adds a reference to schemaName.tableName to the domain at domainIndex.

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) DeleteIndex added in v1.0.86

func (se *SchemaEditor) DeleteIndex(schemaIndex, tableIndex int, name string) bool

DeleteIndex removes an index 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) DeleteScript added in v1.0.86

func (se *SchemaEditor) DeleteScript(schemaIndex, at int) bool

DeleteScript removes the script at position at.

func (*SchemaEditor) DeleteSequence added in v1.0.86

func (se *SchemaEditor) DeleteSequence(schemaIndex, at int) bool

DeleteSequence removes the sequence at position at.

func (*SchemaEditor) DeleteTable

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

DeleteTable removes a table from a schema

func (*SchemaEditor) DeleteView added in v1.0.86

func (se *SchemaEditor) DeleteView(schemaIndex, at int) bool

DeleteView removes the view at position at.

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) SaveIndex added in v1.0.86

func (se *SchemaEditor) SaveIndex(schemaIndex, tableIndex int, oldName string, idx *models.Index) error

SaveIndex adds an index to a table. When oldName is non-empty the index of that name is replaced (and renamed if needed).

func (*SchemaEditor) SaveScript added in v1.0.86

func (se *SchemaEditor) SaveScript(schemaIndex, at int, s *models.Script) error

SaveScript adds a script to a schema, or replaces the one at position at (use -1 to add).

func (*SchemaEditor) SaveSequence added in v1.0.86

func (se *SchemaEditor) SaveSequence(schemaIndex, at int, s *models.Sequence) error

SaveSequence adds a sequence to a schema, or replaces the one at position at (use -1 to add).

func (*SchemaEditor) SaveView added in v1.0.86

func (se *SchemaEditor) SaveView(schemaIndex, at int, v *models.View) error

SaveView adds a view to a schema, or replaces the one at position at (use -1 to add).

func (*SchemaEditor) UnassignTableFromDomain added in v1.0.86

func (se *SchemaEditor) UnassignTableFromDomain(domainIndex int, schemaName, tableName string) bool

UnassignTableFromDomain removes the reference to schemaName.tableName from the domain.

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