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 ¶
- func BuildConnString(f ConnFields, mask bool) string
- func ExpandHome(p string) string
- func FormatExtensions(format string) []string
- func IsDirectoryFormat(format string) bool
- func MatchesExtension(name string, exts []string) bool
- func ResolveStart(input string) (dir, name string)
- func SSLModes(kind ConnKind) []string
- func TestConnection(f ConnFields) error
- type ConnFields
- type ConnKind
- type FileBrowserConfig
- type FileBrowserMode
- type FileEntry
- type LoadConfig
- type SaveConfig
- type SchemaEditor
- func (se *SchemaEditor) AssignTableToDomain(domainIndex int, schemaName, tableName string) error
- func (se *SchemaEditor) CreateColumn(schemaIndex, tableIndex int, name, dataType string, ...) *models.Column
- func (se *SchemaEditor) CreateRelationship(schemaIndex, tableIndex int, rel *models.Relationship) *models.Relationship
- func (se *SchemaEditor) CreateSchema(name, description string) *models.Schema
- func (se *SchemaEditor) CreateTable(schemaIndex int, name, description string) *models.Table
- func (se *SchemaEditor) DeleteColumn(schemaIndex, tableIndex int, columnName string) bool
- func (se *SchemaEditor) DeleteIndex(schemaIndex, tableIndex int, name string) bool
- func (se *SchemaEditor) DeleteRelationship(schemaIndex, tableIndex int, relName string) bool
- func (se *SchemaEditor) DeleteSchema(schemaIndex int) bool
- func (se *SchemaEditor) DeleteScript(schemaIndex, at int) bool
- func (se *SchemaEditor) DeleteSequence(schemaIndex, at int) bool
- func (se *SchemaEditor) DeleteTable(schemaIndex, tableIndex int) bool
- func (se *SchemaEditor) DeleteView(schemaIndex, at int) bool
- func (se *SchemaEditor) GetAllColumns(schemaIndex, tableIndex int) map[string]*models.Column
- func (se *SchemaEditor) GetAllSchemas() []*models.Schema
- func (se *SchemaEditor) GetAllTables() []*models.Table
- func (se *SchemaEditor) GetColumn(schemaIndex, tableIndex int, columnName string) *models.Column
- func (se *SchemaEditor) GetDatabase() *models.Database
- func (se *SchemaEditor) GetRelationship(schemaIndex, tableIndex int, relName string) *models.Relationship
- func (se *SchemaEditor) GetRelationshipNames(schemaIndex, tableIndex int) []string
- func (se *SchemaEditor) GetSchema(schemaIndex int) *models.Schema
- func (se *SchemaEditor) GetTable(schemaIndex, tableIndex int) *models.Table
- func (se *SchemaEditor) GetTablesInSchema(schemaIndex int) []*models.Table
- func (se *SchemaEditor) Run() error
- func (se *SchemaEditor) SaveIndex(schemaIndex, tableIndex int, oldName string, idx *models.Index) error
- func (se *SchemaEditor) SaveScript(schemaIndex, at int, s *models.Script) error
- func (se *SchemaEditor) SaveSequence(schemaIndex, at int, s *models.Sequence) error
- func (se *SchemaEditor) SaveView(schemaIndex, at int, v *models.View) error
- func (se *SchemaEditor) UnassignTableFromDomain(domainIndex int, schemaName, tableName string) bool
- func (se *SchemaEditor) UpdateColumn(schemaIndex, tableIndex int, oldName, newName, dataType string, ...) bool
- func (se *SchemaEditor) UpdateRelationship(schemaIndex, tableIndex int, oldName string, rel *models.Relationship) bool
- func (se *SchemaEditor) UpdateSchema(schemaIndex int, name, owner, description string)
- func (se *SchemaEditor) UpdateTable(schemaIndex, tableIndex int, name, description string)
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
ExpandHome replaces a leading ~ with the user's home directory.
func FormatExtensions ¶ added in v1.0.86
FormatExtensions returns the extensions for a format, or nil (no filter) if unknown.
func IsDirectoryFormat ¶ added in v1.0.86
IsDirectoryFormat reports whether a format can be loaded from or saved to a directory.
func MatchesExtension ¶ added in v1.0.86
MatchesExtension reports whether name has one of exts (case-insensitive). An empty extension list matches everything.
func ResolveStart ¶ added in v1.0.86
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 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.
func DetectConnKind ¶ added in v1.0.86
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 LoadConfig ¶
LoadConfig holds the configuration for loading a database
type SaveConfig ¶
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) 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
Source Files
¶
- column_dataops.go
- column_screens.go
- connstring.go
- connstring_check.go
- connstring_screens.go
- database_dataops.go
- database_screens.go
- dialogs.go
- doc.go
- domain_dataops.go
- domain_screens.go
- editor.go
- filebrowser.go
- filebrowser_screens.go
- load_save_screens.go
- main_menu.go
- object_dataops.go
- object_screens.go
- relation_dataops.go
- relation_screens.go
- schema_dataops.go
- schema_screens.go
- table_dataops.go
- table_screens.go