app

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: 0BSD Imports: 14 Imported by: 0

Documentation

Overview

Package app provides the main application logic for the sqlite browser.

Index

Constants

View Source
const (
	PageSize = 20
)

Variables

View Source
var (
	TitleStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("#FAFAFA")).
				Background(lipgloss.Color("#7D56F4")).
				Padding(0, 1)

	SelectedStyle = lipgloss.NewStyle().
					Bold(true).
					Foreground(lipgloss.Color("#FAFAFA")).
					Background(lipgloss.Color("#F25D94"))

	NormalStyle = lipgloss.NewStyle().
				Foreground(lipgloss.Color("#FAFAFA"))

	ErrorStyle = lipgloss.NewStyle().
				Foreground(lipgloss.Color("#FF0000")).
				Bold(true)

	HelpStyle = lipgloss.NewStyle().
				Foreground(lipgloss.Color("#626262"))
)

Styles

Functions

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func TruncateString

func TruncateString(s string, maxLen int) string

func WrapText

func WrapText(text string, width int) []string

Types

type AppKeyMap

type AppKeyMap struct {
	Quit       key.Binding
	Suspend    key.Binding
	ToggleHelp key.Binding
}

AppKeyMap defines the keybindings for the application

func DefaultAppKeyMap

func DefaultAppKeyMap() AppKeyMap

DefaultAppKeyMap returns the default keybindings

type EditCellKeyMap

type EditCellKeyMap struct {
	Save        key.Binding
	Cancel      key.Binding
	CursorLeft  key.Binding
	CursorRight key.Binding
	WordLeft    key.Binding
	WordRight   key.Binding
	LineStart   key.Binding
	LineEnd     key.Binding
	DeleteWord  key.Binding
	DeleteChar  key.Binding
	ToggleHelp  key.Binding
}

EditCellKeyMap defines keybindings for the edit cell view

func DefaultEditCellKeyMap

func DefaultEditCellKeyMap() EditCellKeyMap

DefaultEditCellKeyMap returns the default keybindings for edit cell

func (EditCellKeyMap) FullHelp

func (k EditCellKeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view

func (EditCellKeyMap) ShortHelp

func (k EditCellKeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view

type EditCellModel

type EditCellModel struct {
	Shared *SharedData
	// contains filtered or unexported fields
}

func NewEditCellModel

func NewEditCellModel(shared *SharedData, rowIndex, colIndex int, opts ...EditCellOption) *EditCellModel

func (*EditCellModel) Blur

func (m *EditCellModel) Blur()

Blur removes focus

func (*EditCellModel) Focus

func (m *EditCellModel) Focus()

Focus sets the focus state

func (EditCellModel) Focused

func (m EditCellModel) Focused() bool

Focused returns the focus state

func (EditCellModel) ID

func (m EditCellModel) ID() int

ID returns the unique ID of the model

func (*EditCellModel) Init

func (m *EditCellModel) Init() tea.Cmd

func (*EditCellModel) Update

func (m *EditCellModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*EditCellModel) View

func (m *EditCellModel) View() string

type EditCellOption

type EditCellOption func(*EditCellModel)

EditCellOption is a functional option for configuring EditCellModel

func WithEditCellKeyMap

func WithEditCellKeyMap(km EditCellKeyMap) EditCellOption

WithEditCellKeyMap sets the key map

type ExecuteQueryMsg

type ExecuteQueryMsg struct{ Query string }

Custom message types

type Model

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

Model is the main application model

func InitialModel

func InitialModel(db *sql.DB, opts ...Option) *Model

func (*Model) Blur

func (m *Model) Blur()

Blur removes focus from the application

func (*Model) Err

func (m *Model) Err() error

func (*Model) Focus

func (m *Model) Focus()

Focus sets the focus state of the application

func (Model) Focused

func (m Model) Focused() bool

Focused returns the focus state

func (*Model) Init

func (m *Model) Init() tea.Cmd

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Model) View

func (m *Model) View() string

type Option

type Option func(*Model)

Option is a functional option for configuring the Model

func WithDimensions

func WithDimensions(width, height int) Option

WithDimensions sets the initial dimensions

func WithKeyMap

func WithKeyMap(km AppKeyMap) Option

WithKeyMap sets the key map for the application

type QueryCompletedMsg

type QueryCompletedMsg struct {
	Results [][]string
	Columns []string
	Error   error
}

Custom message types

type QueryKeyMap

type QueryKeyMap struct {
	// Input mode keys
	Execute     key.Binding
	Escape      key.Binding
	CursorLeft  key.Binding
	CursorRight key.Binding
	WordLeft    key.Binding
	WordRight   key.Binding
	LineStart   key.Binding
	LineEnd     key.Binding
	DeleteWord  key.Binding

	// Results mode keys
	Up         key.Binding
	Down       key.Binding
	Enter      key.Binding
	EditQuery  key.Binding
	GoToStart  key.Binding
	GoToEnd    key.Binding
	Back       key.Binding
	ToggleHelp key.Binding
}

QueryKeyMap defines keybindings for the query view. Navigation follows vim-like patterns: - gg: go to start (requires two 'g' presses) - G: go to end (single 'G' press)

func DefaultQueryKeyMap

func DefaultQueryKeyMap() QueryKeyMap

DefaultQueryKeyMap returns the default keybindings for query view

func (QueryKeyMap) FullHelp

func (k QueryKeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view

func (QueryKeyMap) ShortHelp

func (k QueryKeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view

type QueryModel

type QueryModel struct {
	Shared *SharedData

	FocusOnInput bool
	// contains filtered or unexported fields
}

func NewQueryModel

func NewQueryModel(shared *SharedData, opts ...QueryOption) *QueryModel

func (*QueryModel) Blur

func (m *QueryModel) Blur()

Blur removes focus

func (*QueryModel) Focus

func (m *QueryModel) Focus()

Focus sets the focus state

func (QueryModel) Focused

func (m QueryModel) Focused() bool

Focused returns the focus state

func (QueryModel) ID

func (m QueryModel) ID() int

ID returns the unique ID of the model

func (*QueryModel) Init

func (m *QueryModel) Init() tea.Cmd

func (*QueryModel) Update

func (m *QueryModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*QueryModel) View

func (m *QueryModel) View() string

type QueryOption

type QueryOption func(*QueryModel)

QueryOption is a functional option for configuring QueryModel

func WithQueryKeyMap

func WithQueryKeyMap(km QueryKeyMap) QueryOption

WithQueryKeyMap sets the key map

type RefreshDataMsg

type RefreshDataMsg struct{}

Custom message types

type ReturnToQueryMsg

type ReturnToQueryMsg struct{} // Return to query mode from row detail

Custom message types

type RowDetailKeyMap

type RowDetailKeyMap struct {
	Up         key.Binding
	Down       key.Binding
	Enter      key.Binding
	Escape     key.Binding
	Back       key.Binding
	GoToStart  key.Binding
	GoToEnd    key.Binding
	ToggleHelp key.Binding
}

RowDetailKeyMap defines keybindings for the row detail view. Navigation follows vim-like patterns: - gg: go to start (requires two 'g' presses) - G: go to end (single 'G' press)

func DefaultRowDetailKeyMap

func DefaultRowDetailKeyMap() RowDetailKeyMap

DefaultRowDetailKeyMap returns the default keybindings for row detail

func (RowDetailKeyMap) FullHelp

func (k RowDetailKeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view

func (RowDetailKeyMap) ShortHelp

func (k RowDetailKeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view

type RowDetailModel

type RowDetailModel struct {
	Shared *SharedData

	FromQuery bool
	// contains filtered or unexported fields
}

func NewRowDetailModel

func NewRowDetailModel(shared *SharedData, rowIndex int, opts ...RowDetailOption) *RowDetailModel

func (*RowDetailModel) Blur

func (m *RowDetailModel) Blur()

Blur removes focus

func (*RowDetailModel) Focus

func (m *RowDetailModel) Focus()

Focus sets the focus state

func (RowDetailModel) Focused

func (m RowDetailModel) Focused() bool

Focused returns the focus state

func (RowDetailModel) ID

func (m RowDetailModel) ID() int

ID returns the unique ID of the model

func (*RowDetailModel) Init

func (m *RowDetailModel) Init() tea.Cmd

func (*RowDetailModel) Update

func (m *RowDetailModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*RowDetailModel) View

func (m *RowDetailModel) View() string

type RowDetailOption

type RowDetailOption func(*RowDetailModel)

RowDetailOption is a functional option for configuring RowDetailModel

func WithRowDetailKeyMap

func WithRowDetailKeyMap(km RowDetailKeyMap) RowDetailOption

WithRowDetailKeyMap sets the key map

type SharedData

type SharedData struct {
	DB             *sql.DB
	Tables         []string
	FilteredTables []string
	TableData      [][]string
	FilteredData   [][]string
	Columns        []string
	PrimaryKeys    []string
	SelectedTable  int
	TotalRows      int
	CurrentPage    int
	Width          int
	Height         int
	// Query result context
	IsQueryResult  bool
	QueryTableName string // For simple queries, store the source table
}

SharedData that all models need access to

func NewSharedData

func NewSharedData(db *sql.DB) *SharedData

func (*SharedData) LoadTableData

func (s *SharedData) LoadTableData() error

func (*SharedData) LoadTables

func (s *SharedData) LoadTables() error

func (*SharedData) UpdateCell

func (s *SharedData) UpdateCell(rowIndex, colIndex int, newValue string) error

type SwitchToEditCellMsg

type SwitchToEditCellMsg struct{ RowIndex, ColIndex int }

Custom message types

type SwitchToQueryMsg

type SwitchToQueryMsg struct{}

Custom message types

type SwitchToRowDetailFromQueryMsg

type SwitchToRowDetailFromQueryMsg struct{ RowIndex int }

Custom message types

type SwitchToRowDetailMsg

type SwitchToRowDetailMsg struct{ RowIndex int }

Custom message types

type SwitchToTableDataMsg

type SwitchToTableDataMsg struct{ TableIndex int }

Custom message types

type SwitchToTableListClearMsg

type SwitchToTableListClearMsg struct{} // Switch to table list and clear any filter

Custom message types

type SwitchToTableListMsg

type SwitchToTableListMsg struct{}

Custom message types

type TableDataKeyMap

type TableDataKeyMap struct {
	Up         key.Binding
	Down       key.Binding
	Left       key.Binding
	Right      key.Binding
	Enter      key.Binding
	Search     key.Binding
	Escape     key.Binding
	Back       key.Binding
	GoToStart  key.Binding
	GoToEnd    key.Binding
	Refresh    key.Binding
	SQLMode    key.Binding
	ToggleHelp key.Binding
}

TableDataKeyMap defines keybindings for the table data view. Navigation follows vim-like patterns: - gg: go to start (requires two 'g' presses) - G: go to end (single 'G' press)

func DefaultTableDataKeyMap

func DefaultTableDataKeyMap() TableDataKeyMap

DefaultTableDataKeyMap returns the default keybindings for table data

func (TableDataKeyMap) FullHelp

func (k TableDataKeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view

func (TableDataKeyMap) ShortHelp

func (k TableDataKeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view

type TableDataModel

type TableDataModel struct {
	Shared *SharedData
	// contains filtered or unexported fields
}

func NewTableDataModel

func NewTableDataModel(shared *SharedData, opts ...TableDataOption) *TableDataModel

func (*TableDataModel) Blur

func (m *TableDataModel) Blur()

Blur removes focus

func (*TableDataModel) Focus

func (m *TableDataModel) Focus()

Focus sets the focus state

func (TableDataModel) Focused

func (m TableDataModel) Focused() bool

Focused returns the focus state

func (TableDataModel) ID

func (m TableDataModel) ID() int

ID returns the unique ID of the model

func (*TableDataModel) Init

func (m *TableDataModel) Init() tea.Cmd

func (*TableDataModel) Update

func (m *TableDataModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*TableDataModel) View

func (m *TableDataModel) View() string

type TableDataOption

type TableDataOption func(*TableDataModel)

TableDataOption is a functional option for configuring TableDataModel

func WithTableDataKeyMap

func WithTableDataKeyMap(km TableDataKeyMap) TableDataOption

WithTableDataKeyMap sets the key map

type TableListKeyMap

type TableListKeyMap struct {
	Up         key.Binding
	Down       key.Binding
	Left       key.Binding
	Right      key.Binding
	Enter      key.Binding
	Search     key.Binding
	Escape     key.Binding
	GoToStart  key.Binding
	GoToEnd    key.Binding
	Refresh    key.Binding
	SQLMode    key.Binding
	ToggleHelp key.Binding
}

TableListKeyMap defines keybindings for the table list view. Navigation follows vim-like patterns: - gg: go to start (requires two 'g' presses) - G: go to end (single 'G' press)

func DefaultTableListKeyMap

func DefaultTableListKeyMap() TableListKeyMap

DefaultTableListKeyMap returns the default keybindings for table list

func (TableListKeyMap) FullHelp

func (k TableListKeyMap) FullHelp() [][]key.Binding

FullHelp returns keybindings for the expanded help view

func (TableListKeyMap) ShortHelp

func (k TableListKeyMap) ShortHelp() []key.Binding

ShortHelp returns keybindings to be shown in the mini help view

type TableListModel

type TableListModel struct {
	Shared *SharedData
	// contains filtered or unexported fields
}

func NewTableListModel

func NewTableListModel(shared *SharedData, opts ...TableListOption) *TableListModel

func (*TableListModel) Blur

func (m *TableListModel) Blur()

Blur removes focus

func (*TableListModel) Focus

func (m *TableListModel) Focus()

Focus sets the focus state

func (TableListModel) Focused

func (m TableListModel) Focused() bool

Focused returns the focus state

func (TableListModel) ID

func (m TableListModel) ID() int

ID returns the unique ID of the model

func (*TableListModel) Init

func (m *TableListModel) Init() tea.Cmd

func (*TableListModel) Update

func (m *TableListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*TableListModel) View

func (m *TableListModel) View() string

type TableListOption

type TableListOption func(*TableListModel)

TableListOption is a functional option for configuring TableListModel

func WithTableListKeyMap

func WithTableListKeyMap(km TableListKeyMap) TableListOption

WithTableListKeyMap sets the key map

type ToggleHelpMsg

type ToggleHelpMsg struct{} // Toggle between short and full help

Custom message types

type UpdateCellMsg

type UpdateCellMsg struct {
	RowIndex, ColIndex int
	Value              string
}

Custom message types

Jump to

Keyboard shortcuts

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