schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package schema owns the schema sidebar and the structure/index/foreign-key tabs: the loaded schema tree with its filter and accordion animation, the structure tables and their filters, the column/index/foreign-key/table forms, and the relationship diagram. The root shell keeps the query lifecycle (loadSchema, selectSchemaTable, DDL execution, column/index/FK CRUD execution) and the confirmation/delete overlays; it routes pane-local messages into the component and applies the component's typed events.

Index

Constants

View Source
const (
	IndexKindNormal  = "Index"
	IndexKindUnique  = "Unique"
	IndexKindPrimary = "Primary key"
)
View Source
const MaxDiagramDepth = 5

MaxDiagramDepth caps the focus-ring depth of the relationship and index diagrams: each extra ring widens the layout, and the fit fallback covers the rest.

View Source
const TreeAnimFrame = time.Second / 60

TreeAnimFrame is the tick rate of the sidebar accordion animation; it matches the spring's FPS so the simulation runs at real time.

View Source
const TreeAnimMaxTicks = 240

TreeAnimMaxTicks bounds the animation (4s at 60fps) so a stalled spring can never keep the tick loop alive forever.

Variables

This section is empty.

Functions

func AbbreviateCount

func AbbreviateCount(n int64) string

abbreviateCount renders a compact human-readable count: 10k, 490k, 1.23M; up to two decimals with trailing zeros trimmed, raw below 1k.

func ListFilter

func ListFilter(term string, targets []string) []list.Rank

ListFilter is the schema sidebar's list filter; exported for the root tests.

func NewSchemaList

func NewSchemaList() list.Model

NewSchemaList builds a fresh schema sidebar list.

func SetNerdFont

func SetNerdFont(enabled bool)

SetNerdFont records whether the session renders Nerd Font glyphs.

func SetTheme added in v1.0.0

func SetTheme()

SetTheme refreshes package-level schema styles after the shared palette changes. It keeps schema delegates created by existing models aligned with the app and uikit theme globals.

Types

type Anim

type Anim struct {
	Spring     harmonica.Spring
	Value      float64 // spring position, 0..1 (may overshoot slightly)
	Velocity   float64
	Ticks      int
	Database   string
	Schema     string // "" animates the whole database subtree
	Collapsing bool
	Total      int // child rows in the animated subtree
}

Anim drives the accordion reveal of a toggled subtree: the child rows of database (all of them, or just schema's tables) appear top-to-bottom when expanding and disappear bottom-to-top when collapsing. The spring is stateless, so the animation keeps the position and velocity itself.

func (*Anim) Complete

func (a *Anim) Complete() bool

Complete reports whether the reveal reached its final state: every child row shown when expanding, none when collapsing.

func (*Anim) RevealedRows

func (a *Anim) RevealedRows() int

RevealedRows returns how many child rows of the animated subtree may render this frame.

type ClickClock

type ClickClock struct {
	Time time.Time
	X, Y int
	Tab  core.Tab
	Row  int
}

ClickClock is the root's shared click-tracking state for the workspace tables: the last press position, tab, and row. The root stores it in its layout state; the component reads and updates it during table clicks so double-click detection stays identical to the pre-refactor root logic.

type ColumnDeleteRequested

type ColumnDeleteRequested struct{ Name string }

ColumnDeleteRequested asks the root to confirm deleting the structure column at the table cursor.

type ColumnForm

type ColumnForm struct {
	Form         *huh.Form
	Confirmation *uikit.ConfirmationDialog
	Values       *ColumnFormValues

	PreviousName, OriginalType  string
	OriginalAttributes          string
	TypeOptions                 []sharedsql.ColumnType
	ValidationError             string
	Width, Height, ScrollOffset int

	HadDefault, TypeChanged, Saving bool
	IsNew                           bool
	ConfirmationSave                bool
	ConfirmationDelete              bool
	// contains filtered or unexported fields
}

ColumnForm is the structure tab's add/edit column form: the huh form, its values, the save/discard confirmation, the type options, and the geometry. The root owns the confirmation overlay and the DDL execution; the component owns the form construction, key routing, and validation.

func NewColumnForm

func NewColumnForm(column sharedsql.ColumnInfo, typeOptions []sharedsql.ColumnType) ColumnForm

func NewEmptyColumnForm

func NewEmptyColumnForm(typeOptions []sharedsql.ColumnType) ColumnForm

func (ColumnForm) Active

func (f ColumnForm) Active() bool

Active reports whether the form holds fields.

func (ColumnForm) Change

func (f ColumnForm) Change() (sharedsql.ColumnChange, error)

Change builds the persisted column change, validating it.

func (ColumnForm) ColumnDef

func (f ColumnForm) ColumnDef() (sharedsql.ColumnDef, error)

ColumnDef builds the new-column definition, validating it.

func (ColumnForm) Confirming

func (f ColumnForm) Confirming() bool

Confirming reports whether the save/discard confirmation is open.

func (ColumnForm) FieldCount

func (f ColumnForm) FieldCount() int

FieldCount returns the number of form fields.

func (ColumnForm) FieldTitles

func (f ColumnForm) FieldTitles() []string

FieldTitles lists the rendered titles of every column form field in render order; parameter titles come from the selected type.

func (*ColumnForm) Focus

func (f *ColumnForm) Focus() tea.Cmd

Focus focuses the focused field.

func (*ColumnForm) FocusField

func (f *ColumnForm) FocusField(field int) tea.Cmd

FocusField moves the field cursor to the field at index. The loop bounds guard against Huh navigation skipping fields.

func (ColumnForm) FocusedField

func (f ColumnForm) FocusedField() int

FocusedField returns the index of the focused field.

func (ColumnForm) HasChanges

func (f ColumnForm) HasChanges() bool

HasChanges reports whether the form differs from the values it was opened with, in ways a save would persist. Type parameters count only when the type was re-selected or the column had no recorded type, mirroring typeDeclaration.

func (*ColumnForm) NextField

func (f *ColumnForm) NextField() tea.Cmd

NextField advances the field cursor.

func (*ColumnForm) PreviousField

func (f *ColumnForm) PreviousField() tea.Cmd

PreviousField retreats the field cursor.

func (*ColumnForm) RebuildForm

func (f *ColumnForm) RebuildForm()

RebuildForm rebuilds the huh form from the current values.

func (*ColumnForm) ScrollToField

func (f *ColumnForm) ScrollToField(field int)

ScrollToField moves the viewport offset so the field at index is visible.

func (*ColumnForm) SelectType

func (f *ColumnForm) SelectType(index int, values []string)

SelectType selects the type option at index and seeds its parameters.

func (*ColumnForm) SetHeight

func (f *ColumnForm) SetHeight(height int)

SetHeight caps the form to the given viewport height.

func (*ColumnForm) SetKeys

func (f *ColumnForm) SetKeys(keys uikit.KeyMatcher)

SetKeys installs the session keybindings for the form's bindings.

func (*ColumnForm) SetWidth

func (f *ColumnForm) SetWidth(width int)

SetWidth refits the form to the given content width.

func (ColumnForm) TypeChoices

func (f ColumnForm) TypeChoices() []huh.Option[string]

TypeChoices renders the selectable type options.

func (*ColumnForm) Update

func (f *ColumnForm) Update(message tea.Msg, controller *uikit.FormModeController) (tea.Cmd, ColumnFormAction)

Update routes one message through the column form: the confirmation, the Save/Cancel bar, the modal modes, and the field navigation. The controller is the session's shared form-mode controller; the root keeps it current for the mode badge and the button bar.

func (ColumnForm) View

func (f ColumnForm) View() string

View renders the column form body.

type ColumnFormAction

type ColumnFormAction uint8

ColumnFormAction is the outcome of one column form update the root acts on: saving/altering the column, discarding, or deleting it.

const (
	ColumnFormNoAction ColumnFormAction = iota
	ColumnFormSave
	ColumnFormDiscard
	ColumnFormDelete
)

type ColumnFormRequested

type ColumnFormRequested struct{}

ColumnFormRequested asks the root to open the edit form for the selected structure column through its form-mode wrapper.

type ColumnFormValues

type ColumnFormValues struct {
	Name, TypeName, DefaultValue, Attributes string
	Parameters                               []string
	Nullable                                 bool
}

ColumnFormValues is the editable column state of the structure form.

type ContextMenuRequested

type ContextMenuRequested struct{ Menu Menu }

ContextMenuRequested asks the root to open a schema context menu.

type DatabaseSelected

type DatabaseSelected struct{ Database string }

DatabaseSelected asks the root to open the database scope of the sidebar root: clear the table workspace and target the database. SQLite roots never emit it (their workspace stays SQL-only until a table opens), PostgreSQL roots only when they are the connected database, and unknown/non-built-in products only when the driver advertises workspace metadata.

type DeleteTableRequested

type DeleteTableRequested struct {
	Database string
	Table    string
}

DeleteTableRequested asks the root to confirm dropping the given table.

type Event

type Event = any

Event is the component's update result: a typed request to the root shell. It is an alias for any so the component can emit the shared uikit events (uikit.StatusChanged, uikit.ClipboardRequested) alongside its own schema-local events; the root type-switches the concrete type.

type ForeignKeyDeleteRequested

type ForeignKeyDeleteRequested struct{ ID string }

ForeignKeyDeleteRequested asks the root to confirm deleting the foreign key at the foreign-keys table cursor.

type ForeignKeyForm

type ForeignKeyForm struct {
	Form         *huh.Form
	Confirmation *uikit.ConfirmationDialog
	Values       *ForeignKeyFormValues

	Previous                             string
	Width, Height                        int
	ScrollOffset                         int
	Saving                               bool
	ConfirmationSave, ConfirmationDelete bool
	// contains filtered or unexported fields
}

ForeignKeyForm is the foreign-keys tab's create/edit form: the huh form, its values, the save/discard confirmation, and the geometry. The root owns the confirmation overlay and the DDL execution.

func NewForeignKeyForm

func NewForeignKeyForm(foreignKey *sharedsql.ForeignKeyInfo) ForeignKeyForm

func (ForeignKeyForm) Active

func (f ForeignKeyForm) Active() bool

Active reports whether the form holds fields.

func (ForeignKeyForm) Change

Change builds the persisted foreign-key change, validating it.

func (*ForeignKeyForm) Close

func (f *ForeignKeyForm) Close()

Close drops the form.

func (ForeignKeyForm) Confirming

func (f ForeignKeyForm) Confirming() bool

Confirming reports whether the save/discard confirmation is open.

func (ForeignKeyForm) FieldTitles

func (f ForeignKeyForm) FieldTitles() []string

FieldTitles lists the rendered titles of every foreign-key form field in render order.

func (*ForeignKeyForm) Focus

func (f *ForeignKeyForm) Focus() tea.Cmd

Focus focuses the focused field.

func (*ForeignKeyForm) FocusField

func (f *ForeignKeyForm) FocusField(field int) tea.Cmd

FocusField moves the field cursor to the field at index. The loop bounds guard against Huh navigation skipping fields.

func (ForeignKeyForm) HasChanges

func (f ForeignKeyForm) HasChanges() bool

HasChanges reports whether the form differs from the values it was opened with.

func (*ForeignKeyForm) ScrollToField

func (f *ForeignKeyForm) ScrollToField(field int)

ScrollToField keeps the rendered block of the field at index visible by moving the viewport offset to its title line.

func (*ForeignKeyForm) SetKeys

func (f *ForeignKeyForm) SetKeys(keys uikit.KeyMatcher)

SetKeys installs the session keybindings for the form's bindings.

func (*ForeignKeyForm) SetWidth

func (f *ForeignKeyForm) SetWidth(width int)

SetWidth refits the form to the given content width.

func (*ForeignKeyForm) Update

func (f *ForeignKeyForm) Update(message tea.Msg, controller *uikit.FormModeController) (tea.Cmd, ForeignKeyFormAction)

Update routes one message through the foreign-key form.

func (ForeignKeyForm) View

func (f ForeignKeyForm) View() string

View renders the foreign-key form body.

type ForeignKeyFormAction

type ForeignKeyFormAction uint8

ForeignKeyFormAction is the outcome of one foreign-key form update the root acts on.

const (
	ForeignKeyFormNoAction ForeignKeyFormAction = iota
	ForeignKeyFormSave
	ForeignKeyFormDiscard
	ForeignKeyFormDelete
)

type ForeignKeyFormRequested

type ForeignKeyFormRequested struct{ Selected bool }

ForeignKeyFormRequested asks the root to open the foreign-key form through its form-mode wrapper: Selected edits the foreign key at the table cursor, an unset flag creates a new one.

type ForeignKeyFormValues

type ForeignKeyFormValues struct {
	Columns, ReferenceTable, ReferenceColumns string
	OnDelete, OnUpdate                        string
}

ForeignKeyFormValues is the editable foreign-key state of the form.

type IndexDeleteRequested

type IndexDeleteRequested struct{ Name string }

IndexDeleteRequested asks the root to confirm deleting the index at the indexes table cursor.

type IndexForm

type IndexForm struct {
	Form         *huh.Form
	Confirmation *uikit.ConfirmationDialog
	Values       *IndexFormValues

	Previous           string
	Width, Height      int
	ScrollOffset       int
	Saving             bool
	ConfirmationSave   bool
	ConfirmationDelete bool
	// contains filtered or unexported fields
}

IndexForm is the indexes tab's create/edit index form: the huh form, its values, the save/discard confirmation, and the geometry. The root owns the confirmation overlay and the DDL execution.

func NewIndexForm

func NewIndexForm(index *sharedsql.IndexInfo) IndexForm

func (IndexForm) Active

func (f IndexForm) Active() bool

Active reports whether the form holds fields.

func (IndexForm) Change

func (f IndexForm) Change() (sharedsql.IndexChange, error)

Change builds the persisted index change, validating it.

func (*IndexForm) Close

func (f *IndexForm) Close()

Close drops the form.

func (IndexForm) Confirming

func (f IndexForm) Confirming() bool

Confirming reports whether the save/discard confirmation is open.

func (IndexForm) FieldTitles

func (f IndexForm) FieldTitles() []string

FieldTitles lists the rendered titles of every index form field in render order.

func (*IndexForm) Focus

func (f *IndexForm) Focus() tea.Cmd

Focus focuses the focused field.

func (*IndexForm) FocusField

func (f *IndexForm) FocusField(field int) tea.Cmd

FocusField moves the field cursor to the field at index. The loop bounds guard against Huh navigation skipping fields.

func (IndexForm) HasChanges

func (f IndexForm) HasChanges() bool

HasChanges reports whether the form differs from the values it was opened with.

func (*IndexForm) ScrollToField

func (f *IndexForm) ScrollToField(field int)

ScrollToField keeps the rendered block of the field at index visible by moving the viewport offset to its title line.

func (*IndexForm) SetKeys

func (f *IndexForm) SetKeys(keys uikit.KeyMatcher)

SetKeys installs the session keybindings for the form's bindings.

func (*IndexForm) SetWidth

func (f *IndexForm) SetWidth(width int)

SetWidth refits the form to the given content width.

func (*IndexForm) Update

func (f *IndexForm) Update(message tea.Msg, controller *uikit.FormModeController) (tea.Cmd, IndexFormAction)

Update routes one message through the index form.

func (IndexForm) View

func (f IndexForm) View() string

View renders the index form body.

type IndexFormAction

type IndexFormAction uint8

IndexFormAction is the outcome of one index form update the root acts on.

const (
	IndexFormNoAction IndexFormAction = iota
	IndexFormSave
	IndexFormDiscard
	IndexFormDelete
)

type IndexFormRequested

type IndexFormRequested struct{ Selected bool }

IndexFormRequested asks the root to open the index form through its form-mode wrapper: Selected edits the index at the table cursor, an unset flag creates a new one.

type IndexFormValues

type IndexFormValues struct {
	Name, Columns string
	Kind          string
}

IndexFormValues is the editable index state of the index form.

type Item

type Item struct {
	Name, Detail    string
	Database, Table string
	Schema          string
	Kind            string
	Root            bool
	Open            bool   // on the path from the root to the open table
	Count           int    // child tables/views; -1 = unknown (not rendered)
	RowCount        *int64 // estimated rows for tables; nil = unknown
}

Item is one row of the schema sidebar tree: a database root, a PostgreSQL schema, or a table/view. Positional fields feed the list filter.

func (Item) Description

func (i Item) Description() string

func (Item) FilterValue

func (i Item) FilterValue() string

func (Item) Title

func (i Item) Title() string

type ItemDelegate

type ItemDelegate = schemaItemDelegate

schemaItemDelegate renders each tree level with its own marker (database, schema, table/view); state is conveyed by color: muted when idle, secondary on the open table's path, primary when selected. ItemDelegate renders the schema tree rows; exported for the root tests.

type Menu struct {
	Options  []MenuOption
	X, Y     int
	Database string
	Schema   string
	Table    string
}

Menu is a schema context menu the component builds; the root owns the overlay model and dispatch.

type MenuOption struct {
	Label  string
	Action string
	Keys   string
}

MenuOption is one selectable action of a schema context menu; the root renders the menu and dispatches the action strings.

type Model

type Model struct {
	List              list.Model
	Filter            textinput.Model
	Objects           []sharedsql.SchemaObject
	ExpandedDatabases map[string]bool
	ExpandedSchemas   map[string]bool
	Anim              *Anim
	Structure         Structure
}

Model is the schema feature component: the sidebar list and filter, the loaded schema objects, database/schema expansion and the accordion animation, plus the structure/index/foreign-key state. The root reads and writes the exported state fields and mirrors the workflow's selected table and tab through the Snapshot.

func New

func New() Model

New builds the schema component with a fresh tree list and structure tables.

func (Model) AddTarget

func (m Model) AddTarget(item Item, snapshot Snapshot) (string, bool)

AddTarget returns the qualifier for a new table next to the selected item: the database for SQLite/MySQL, the schema for PostgreSQL (whose sidebar groups tables under database roots).

func (*Model) ApplyFilter

func (m *Model) ApplyFilter()

ApplyFilter pushes the visible filter input's value into the schema list, which filters its items and reports the committed state the status line mirrors.

func (*Model) ApplyTableFilter

func (m *Model) ApplyTableFilter(tab core.Tab)

ApplyTableFilter re-filters the tab's table from its source rows.

func (Model) BlankMenu

func (m Model) BlankMenu(x, y int) Menu

BlankMenu is the blank-sidebar context menu: creating a database is valid on any server product and needs no selection.

func (*Model) CloseTableFilter

func (m *Model) CloseTableFilter()

CloseTableFilter ends table-filter editing.

func (Model) Draw

func (m Model) Draw(canvas uv.ScreenBuffer, layout uikit.Layout)

Draw renders nothing: the schema pane is a lipgloss pane; its overlays (confirmations, context menus) are drawn by the root from the shared uikit dialogs. The contract mirrors the other feature components.

func (Model) FilterRow

func (m Model) FilterRow(layout uikit.Layout) string

FilterRow renders the schema sidebar's filter input, omitted when the pane is too narrow to show it.

func (Model) FilterShown

func (m Model) FilterShown(layout uikit.Layout) bool

FilterShown reports whether the pane is wide enough for the filter box (3 rows: top border, input, bottom border).

func (Model) ForeignKeysView

func (m Model) ForeignKeysView(layout uikit.Layout, offset int, snapshot Snapshot) string

ForeignKeysView renders the foreign-keys tab: the foreign-key form when active, the relationship diagram when toggled, otherwise the foreign-keys table with its filter status line.

func (Model) HandleSchemaClick

func (m Model) HandleSchemaClick(x, contentY int, layout uikit.Layout, snapshot Snapshot, recordFormClick func(x, y int) bool) (Model, Event, tea.Cmd)

HandleSchemaClick maps a schema-pane click to its item. A double-click on a PostgreSQL root that is not the connected database reconnects to it (matching the recent list's double-click-to-load); any other root or schema click toggles the subtree and emits the scope selection event, and a table click selects it. recordFormClick is the root's double-click detector, consulted only for root items like the original click path.

func (Model) HandleSchemaRightClick

func (m Model) HandleSchemaRightClick(absX, absY int, layout uikit.Layout, snapshot Snapshot) (Model, Menu, bool)

HandleSchemaRightClick maps a right-click on the schema sidebar to its context menu: the clicked item is selected first so the menu actions act on it, blank space on a server product offers creating a database.

func (Model) HandleTableClick

func (m Model) HandleTableClick(absX, absY int, layout uikit.Layout, tab core.Tab, vimMode bool, schemaWidth int, compact bool, clock ClickClock, snapshot Snapshot) (Model, Event, tea.Cmd, ClickClock, bool)

HandleTableClick handles a left-click on the structure, indexes, or foreignKeys table: row-level selection, and a double-click on the same tab and row emits TableRowActivated so the root opens the row's edit form. hit reports whether the click landed on a data row (the root resets the form mode and blurs the editor only then, matching the original).

func (Model) IndexDiagramView

func (m Model) IndexDiagramView(layout uikit.Layout, snapshot Snapshot) string

IndexDiagramView renders the indexes-tab focus diagram, falling back to the flat table/index list when the diagram does not fit the workspace.

func (Model) IndexesView

func (m Model) IndexesView(layout uikit.Layout, offset int, snapshot Snapshot) string

IndexesView renders the indexes tab: the index form when active, the indexes diagram when toggled, otherwise the indexes table with its filter status line.

func (*Model) ItemAt

func (m *Model) ItemAt(contentY int, layout uikit.Layout) (Item, bool)

ItemAt maps a schema-pane Y coordinate to its item, using the same visible/filter/pagination mapping as the rendered sidebar, and selects it.

func (Model) ItemMenu

func (m Model) ItemMenu(item Item, x, y int, snapshot Snapshot) (Menu, bool)

ItemMenu builds the schema context menu for the given item: each tree level offers its sibling, child, edit, and delete operations. SQLite keeps the table-only menu; views expose no menu. ok is false when the item has no menu.

func (Model) ItemOffset

func (m Model) ItemOffset(layout uikit.Layout) int

ItemOffset returns the content Y of the first schema item line: the pane title row plus the 3-row filter box (when shown). The list's status bar is hidden, so nothing else precedes the items.

func (Model) OpenColumnForm

func (m Model) OpenColumnForm(snapshot Snapshot, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenColumnForm opens the edit form for the selected structure column, returning the form's init command (or nil when no column is selected).

func (Model) OpenDatabaseForm

func (m Model) OpenDatabaseForm(originalName string, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenDatabaseForm opens the create/rename database popup.

func (Model) OpenForeignKeyForm

func (m Model) OpenForeignKeyForm(foreignKey *sharedsql.ForeignKeyInfo, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenForeignKeyForm opens the create/edit foreign-key form, returning its init command.

func (Model) OpenIndexForm

func (m Model) OpenIndexForm(index *sharedsql.IndexInfo, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenIndexForm opens the create/edit index form, returning its init command.

func (Model) OpenNewColumnForm

func (m Model) OpenNewColumnForm(snapshot Snapshot, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenNewColumnForm opens the add-column form, returning its init command.

func (Model) OpenSchemaForm

func (m Model) OpenSchemaForm(originalName string, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenSchemaForm opens the create/rename schema popup.

func (*Model) OpenTableFilter

func (m *Model) OpenTableFilter(tab core.Tab) tea.Cmd

OpenTableFilter starts editing the active tab's table filter.

func (Model) OpenTableForm

func (m Model) OpenTableForm(database, table string, layout uikit.Layout, keys uikit.KeyMatcher) (Model, tea.Cmd)

OpenTableForm opens the create/rename table popup. The popup's init command is dropped, like the original openPopup; the root starts insert mode through the form-mode controller.

func (*Model) RebuildTree

func (m *Model) RebuildTree(snapshot Snapshot) tea.Cmd

RebuildTree rebuilds the sidebar list from the loaded objects, applying the expansion state and the accordion reveal budget.

func (*Model) RefreshTheme

func (m *Model) RefreshTheme()

RefreshTheme re-applies the shared theme styles to the schema list and any open schema forms after the root switches the palette. The root calls it from its theme apply path, matching the pre-refactor list re-theming.

func (Model) RelationshipView

func (m Model) RelationshipView(layout uikit.Layout, snapshot Snapshot) string

RelationshipView renders the relationship diagram, falling back to the flat relationship list when the diagram does not fit the workspace.

func (*Model) Reset

func (m *Model) Reset()

Reset clears the schema sidebar (loaded objects, expansion, the tree list, and the filter input) and the structure, index, and foreign-key tables.

func (*Model) ResetTableFilter

func (m *Model) ResetTableFilter(tab core.Tab)

ResetTableFilter clears the active tab's table filter.

func (*Model) Resize

func (m *Model) Resize(layout uikit.Layout)

Resize refits the schema list and filter to the pane geometry. The equations mirror the root layout pass exactly: the list spans the pane body below the filter box (3 rows when the pane is wide enough).

func (*Model) ResizeTables

func (m *Model) ResizeTables(width, height int)

ResizeTables fits the structure, index, and foreign-key tables to the workspace viewport. The height equation is preserved from the root layout pass: the tab tables yield one row to the blank line that separates their status line from the mode/tab-hint footer.

func (Model) RowY

func (m Model) RowY(index int, layout uikit.Layout) int

RowY returns the screen Y of the schema list item at the given index, clamped to the visible window.

func (Model) SchemaCollapse

func (m Model) SchemaCollapse(snapshot Snapshot) (Model, tea.Cmd)

SchemaCollapse collapses the selected node when expanded (with the accordion animation) or moves the cursor up to its parent row: the schema for a PostgreSQL table, the database root for anything else. Roots that are already collapsed are a no-op.

func (Model) SchemaExpand

func (m Model) SchemaExpand(snapshot Snapshot) (Model, tea.Cmd)

SchemaExpand expands the selected node when collapsed (with the accordion animation) or moves the cursor to its first child when already expanded. Leaves are a no-op.

func (Model) SchemaReveal

func (m Model) SchemaReveal() (database, schema string, revealed int)

SchemaReveal reports the animated subtree and how many of its child rows may render this frame; revealed is -1 when no animation is running.

func (Model) SchemaSelect

func (m Model) SchemaSelect(snapshot Snapshot) (Model, Event, tea.Cmd)

SchemaSelect runs the schema.select_table binding: toggling a schema or root (with the accordion), reconnecting to a non-connected PostgreSQL root, or selecting a table. Root and schema toggles also emit the scope selection event so the workspace targets the database or schema.

func (Model) ScopeDiagramView

func (m Model) ScopeDiagramView(layout uikit.Layout, snapshot Snapshot) string

ScopeDiagramView renders the hub-less relationship diagram for the database/schema scope target of the snapshot: every in-scope table/view is a card and only edges between two in-scope tables are drawn, with the FK cardinality labels from the index cache. The diagram falls back to a flat relationship list when it does not fit the workspace. Absent caches render the loading state and an object-less scope the empty state, instead of guessing edges.

func (Model) SelectedColumn

func (m Model) SelectedColumn() *sharedsql.ColumnInfo

SelectedColumn returns the structure column at the table cursor.

func (Model) SelectedForeignKey

func (m Model) SelectedForeignKey() *sharedsql.ForeignKeyInfo

SelectedForeignKey returns the foreign key at the foreign-keys table cursor.

func (Model) SelectedIndex

func (m Model) SelectedIndex() *sharedsql.IndexInfo

SelectedIndex returns the index at the indexes table cursor.

func (*Model) SetObjects

func (m *Model) SetObjects(objects []sharedsql.SchemaObject, snapshot Snapshot) tea.Cmd

SetObjects records the loaded schema objects, computes the load-time expansion, rebuilds the tree, and keeps the cursor on the connected root. It returns the tree rebuild command.

func (*Model) SetTableFilterValue

func (m *Model) SetTableFilterValue(tab core.Tab, value string)

SetTableFilterValue records the active filter text for the tab.

func (Model) StructureView

func (m Model) StructureView(layout uikit.Layout, offset int) string

StructureView renders the structure tab: the column form when active, otherwise the columns table with its filter status line.

func (Model) SupportsCreateDatabase

func (m Model) SupportsCreateDatabase(snapshot Snapshot) bool

SupportsCreateDatabase reports whether the connected product can create databases: MySQL and PostgreSQL only.

func (Model) SupportsSchemas

func (m Model) SupportsSchemas(snapshot Snapshot) bool

SupportsSchemas reports whether the connected product nests tables under schemas (PostgreSQL only).

func (Model) TableFilterStatus

func (m Model) TableFilterStatus(tab core.Tab) string

TableFilterStatus renders the tab's table filter status line.

func (Model) TableFilterValue

func (m Model) TableFilterValue(tab core.Tab) string

TableFilterValue returns the active filter text for the tab.

func (Model) TableName

func (m Model) TableName(item Item, snapshot Snapshot) string

TableName returns the qualified name of a schema item: database.table for MySQL (whose sidebar tables are bare names under database roots), the item's own table name otherwise (SQLite bare names, PostgreSQL schema.table).

func (*Model) ToggleDatabase

func (m *Model) ToggleDatabase(database string, snapshot Snapshot) tea.Cmd

ToggleDatabase expands database when collapsed and collapses it when expanded; expanding one root collapses every other, so at most one database shows children at a time. It returns the accordion tick command.

func (*Model) ToggleSchema

func (m *Model) ToggleSchema(database, schema string, snapshot Snapshot) tea.Cmd

ToggleSchema expands schema when collapsed and collapses it when expanded; expanding one schema collapses every other, so at most one schema shows its tables at a time. It returns the accordion tick command.

func (Model) Update

func (m Model) Update(msg tea.Msg, layout uikit.Layout, keys uikit.KeyMatcher, snapshot Snapshot, preparedArg ...uikit.PreparedKeyStroke) (Model, Event, tea.Cmd)

Update handles the schema sidebar pane keys: the filter input, the tree navigation and expansion/collapse keys, the add/rename/delete-table keys, and the list passthrough. The root routes focusSchema messages here and applies the returned events (TableSelected, ReconnectRequested, ...).

func (Model) UpdateColumnForm

func (m Model) UpdateColumnForm(msg tea.Msg, layout uikit.Layout, formMode *uikit.FormModeController) (Model, ColumnFormAction, tea.Cmd)

UpdateColumnForm drives the open column form: key routing through the form, the saving flag, and close-on-discard. The returned action tells the root which DDL flow to execute (add/alter/delete column).

func (Model) UpdateForeignKeyForm

func (m Model) UpdateForeignKeyForm(msg tea.Msg, layout uikit.Layout, formMode *uikit.FormModeController) (Model, ForeignKeyFormAction, tea.Cmd)

UpdateForeignKeyForm drives the open foreign-key form: key routing through the form, the saving flag, and close-on-discard. The returned action tells the root which DDL flow to execute (save or delete foreign key).

func (Model) UpdateIndexForm

func (m Model) UpdateIndexForm(msg tea.Msg, layout uikit.Layout, formMode *uikit.FormModeController) (Model, IndexFormAction, tea.Cmd)

UpdateIndexForm drives the open index form: key routing through the form, the saving flag, and close-on-discard. The returned action tells the root which DDL flow to execute (save or delete index).

func (*Model) UpdateTableFilter

func (m *Model) UpdateTableFilter(message tea.KeyPressMsg) tea.Cmd

UpdateTableFilter routes one key through the active table filter input and re-applies the filter.

func (Model) UpdateTreeAnim

func (m Model) UpdateTreeAnim(message TreeAnimTickMsg, snapshot Snapshot) (Model, tea.Cmd)

UpdateTreeAnim advances the accordion by one spring step and rebuilds the tree with the revealed rows; the animation ends at the first frame that shows (or hides) every child row, before any overshoot can bounce rows.

func (Model) UpdateWorkspace

func (m Model) UpdateWorkspace(msg tea.Msg, layout uikit.Layout, keys uikit.KeyMatcher, tab core.Tab, snapshot Snapshot, offset *int, preparedArg ...uikit.PreparedKeyStroke) (Model, Event, tea.Cmd)

UpdateWorkspace handles the structure/index/foreign-key tab pane keys: the filter/reset keys, the edit/add/create/delete keys (the form and delete actions emit requests the root applies through its form-mode and overlay wrappers), the table navigation, and the table passthrough. offset is the root-owned horizontal pan offset of the active tab's table.

func (Model) View

func (m Model) View(layout uikit.Layout) string

View renders the schema pane body: the persistent filter row above the schema list. The row is omitted when the pane is too narrow to show it.

type NewColumnFormRequested

type NewColumnFormRequested struct{}

NewColumnFormRequested asks the root to open the add-column form through its form-mode wrapper.

type QueryRequested

type QueryRequested struct {
	Statement string
	ReadOnly  bool
}

QueryRequested asks the root to run a statement through its query lifecycle; ReadOnly marks a schema mutation whose success refreshes the sidebar.

type ReconnectRequested

type ReconnectRequested struct{ Database string }

ReconnectRequested asks the root to switch the PostgreSQL session to another database on the same server.

type SchemaRequested

type SchemaRequested struct{}

SchemaRequested asks the root to reload the schema sidebar.

type SchemaSelected

type SchemaSelected struct {
	Database string
	Schema   string
}

SchemaSelected asks the root to open the PostgreSQL schema scope of the sidebar: clear the table workspace and target the schema.

type Snapshot

type Snapshot struct {
	SelectedTable string
	Database      sharedsql.DatabaseInfo
	Target        string
	ReadOnly      bool
	// WorkspaceTarget is the workspace scope the tabs serve: none, a
	// database, a PostgreSQL schema, or a table. The scope diagram reads
	// it to filter its cards.
	WorkspaceTarget core.WorkspaceTarget
	// DatabaseScopeCapable reports that the active driver advertises
	// explicit workspace metadata, so unknown/non-built-in products may
	// serve a generic database scope. Host-owned: the root sets it from
	// its workspace advertisement, never from the product name.
	DatabaseScopeCapable bool
	// ForeignKeysAll and IndexesAll are the connection-level schema caches:
	// every foreign key and index keyed by table, loaded by the root on
	// connect and refreshed on DDL. Nil when not loaded yet; the diagrams
	// then degrade to the selected table's own data.
	ForeignKeysAll map[string][]sharedsql.ForeignKeyInfo
	IndexesAll     map[string][]sharedsql.IndexInfo
}

Snapshot is the root-owned session state the component reads for one update or render: the open table, the connected database info and target (for PostgreSQL/MySQL product rules), the workspace scope target, and the read-only flag.

type Structure

type Structure struct {
	Table                     table.Model
	Rows                      []table.Row
	Columns                   []sharedsql.ColumnInfo
	Filter                    string
	Indexes                   table.Model
	IndexRows                 []table.Row
	IndexInfo                 []sharedsql.IndexInfo
	IndexesFilter             string
	IndexForm                 IndexForm
	ForeignKeys               table.Model
	ForeignKeyRows            []table.Row
	ForeignKeyInfo            []sharedsql.ForeignKeyInfo
	ReferencingForeignKeyInfo []sharedsql.ReferencingForeignKeyInfo
	ForeignKeysFilter         string
	ForeignKeyForm            ForeignKeyForm
	ColumnForm                ColumnForm
	TableForm                 TableForm
	TableFormRunning          bool
	RelationshipDiagram       bool
	// IndexDiagram switches the indexes tab into its diagram mode.
	IndexDiagram bool
	// DiagramDepth is the focus-ring depth of both diagrams: 1 shows only
	// the selected table's foreign-key neighbors, each extra level widens
	// the ring one hop.
	DiagramDepth     int
	TableFiltering   bool
	TableFilterInput textinput.Model
	TableFilterTab   core.Tab
}

Structure owns the structure/index/foreign-key tabs: their tables, row metadata, filters, forms, the relationship-diagram flag, and the table filter input.

type TableForm

type TableForm struct {
	Form         *huh.Form
	Confirmation *uikit.ConfirmationDialog
	Name         string

	OriginalName  string
	Database      string
	Table         string // qualified old name for table renames
	ObjectKind    TableFormObjectKind
	Width, Height int
	// contains filtered or unexported fields
}

TableForm is the create/rename popup for tables, databases, and schemas. Rename mode carries the original name so an unchanged save closes without any SQL. The typed name is kept verbatim for quoted SQL; it is only trimmed to test emptiness and equality. The root builds the DDL statement from the exported fields and runs it through the query lifecycle.

func NewDatabaseForm

func NewDatabaseForm(originalName string) TableForm

func NewSchemaForm

func NewSchemaForm(originalName string) TableForm

func NewTableForm

func NewTableForm(database, table string) TableForm

func (TableForm) Active

func (f TableForm) Active() bool

Active reports whether the popup is open.

func (*TableForm) Close

func (f *TableForm) Close()

Close drops the popup.

func (TableForm) Confirming

func (f TableForm) Confirming() bool

Confirming reports whether the save confirmation is open.

func (*TableForm) Focus

func (f *TableForm) Focus() tea.Cmd

Focus focuses the focused field.

func (*TableForm) SetHeight

func (f *TableForm) SetHeight(height int)

SetHeight caps the popup to the given viewport height.

func (*TableForm) SetKeys

func (f *TableForm) SetKeys(keys uikit.KeyMatcher)

SetKeys installs the session keybindings for the popup's bindings.

func (*TableForm) SetWidth

func (f *TableForm) SetWidth(width int)

SetWidth refits the popup to the given content width.

func (*TableForm) Update

func (f *TableForm) Update(message tea.Msg, controller *uikit.FormModeController) (tea.Cmd, TableFormAction)

Update routes one message through the table popup. Save/Discard flow through the confirmation like the other forms; the root executes the confirmed DDL.

func (TableForm) View

func (f TableForm) View() string

View renders the table popup body.

type TableFormAction

type TableFormAction uint8

TableFormAction is the outcome of one table popup update the root acts on: closing it, opening the save confirmation, or executing the DDL.

const (
	TableFormNoAction TableFormAction = iota
	TableFormClose
	TableFormSave
	TableFormExecute
)

type TableFormObjectKind

type TableFormObjectKind uint8

TableFormObjectKind selects which object the table popup creates or renames.

const (
	TableFormTable TableFormObjectKind = iota
	TableFormDatabase
	TableFormSchema
)

type TableFormRequested

type TableFormRequested struct {
	Kind         TableFormObjectKind
	Database     string // table create target qualifier; database for table renames
	Table        string // qualified old name for table renames
	OriginalName string // database/schema rename target
}

TableFormRequested asks the root to open the create/rename popup for a table, database, or schema through its form-mode wrapper.

type TableRowActivated

type TableRowActivated struct{}

TableRowActivated asks the root to open the edit form for a double-clicked structure/index/foreign-key row, matching the enter/i keybinding behavior.

type TableSelected

type TableSelected struct {
	Table    string
	Database string
	Schema   string
}

TableSelected asks the root to open the given qualified table: select it in the workflow and load its structure, index, and foreign-key data. Database and Schema are the selected item's structured identifiers, preserved so table-scoped workspace views receive the full structured target.

type TreeAnimTickMsg

type TreeAnimTickMsg struct{}

TreeAnimTickMsg advances the sidebar accordion animation by one frame.

Jump to

Keyboard shortcuts

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