db

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExploreModel added in v0.26.0

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

ExploreModel is the Bubble Tea model for the database explorer TUI.

func NewExploreModel added in v0.26.0

func NewExploreModel(s *Session) ExploreModel

NewExploreModel creates a new database explorer TUI model.

func (ExploreModel) Init added in v0.26.0

func (m ExploreModel) Init() tea.Cmd

Init loads the table list.

func (ExploreModel) Update added in v0.26.0

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

Update handles Bubble Tea messages.

func (ExploreModel) View added in v0.26.0

func (m ExploreModel) View() string

View renders the TUI.

type Migration added in v0.26.0

type Migration struct {
	Version  string // e.g., "001"
	Name     string // e.g., "create_users"
	UpFile   string // full path to .up.sql
	DownFile string // full path to .down.sql, may be empty
}

Migration represents a database migration file.

type MigrationStatus added in v0.26.0

type MigrationStatus struct {
	Migration
	Applied bool
}

MigrationStatus is a migration with its applied state.

type Session

type Session struct {
	Driver string
	DSN    string
	Type   string
	// contains filtered or unexported fields
}

Session holds database connection info and an optional native database/sql connection.

func NewSession

func NewSession(cfg *config.Database) (*Session, error)

NewSession creates a new database session from config.

func (*Session) CLI added in v0.12.0

func (s *Session) CLI() string

func (*Session) Close added in v0.19.0

func (s *Session) Close()

Close closes the native database connection if open.

func (*Session) Connect

func (s *Session) Connect() error

Connect opens an interactive database session using the best available CLI. With native drivers compiled in, interactive sessions are the only reason to shell out to external CLIs.

func (*Session) Count

func (s *Session) Count(table, where string) (string, error)

Count returns the count of rows in a table. Table name is validated; WHERE clause is treated as a raw SQL condition (user is responsible for safety).

func (*Session) Describe

func (s *Session) Describe(table string) (string, error)

Describe shows the schema of a table. Table name is validated against the database.

func (*Session) Exec

func (s *Session) Exec(query string) (string, error)

Exec runs a query via an external CLI tool (fallback when no native connection). Prefer using native database/sql queries via the session's methods instead.

func (*Session) ExecCLIQuery added in v0.19.0

func (s *Session) ExecCLIQuery(query, param string) (string, error)

ExecCLIQuery runs a query via the external CLI with a single parameter.

func (*Session) ExecCLIQueryFormatted added in v0.21.0

func (s *Session) ExecCLIQueryFormatted(query, param string) (string, error)

ExecCLIQueryFormatted runs a formatted query via the external CLI with a single parameter.

func (*Session) ExecFormatted added in v0.21.0

func (s *Session) ExecFormatted(query string) (string, error)

ExecFormatted runs a query with tabular formatting via an external CLI tool (fallback when no native connection). Prefer using native database/sql queries via the session's methods instead.

func (*Session) ExecNative added in v0.25.0

func (s *Session) ExecNative(query string) (string, error)

ExecNative runs a raw SQL query via the native connection and returns formatted table results using go-pretty. Returns ("", nil) if no native connection.

func (*Session) ExploreRowCount added in v0.26.0

func (s *Session) ExploreRowCount(table string) (int64, error)

ExploreRowCount returns the total number of rows in a table.

func (*Session) ExploreTable added in v0.26.0

func (s *Session) ExploreTable(table string, limit int) ([]string, [][]string, error)

ExploreTable returns table data for the explore TUI. It fetches column info and a limited number of rows.

func (*Session) Find

func (s *Session) Find(table, id string) (string, error)

Find returns a single row by ID. Table name is validated; ID uses parameterized query.

func (*Session) HasNativeConn added in v0.19.0

func (s *Session) HasNativeConn() bool

HasNativeConn returns true if a native database/sql connection is available.

func (*Session) Indexes added in v0.22.0

func (s *Session) Indexes(table string) (string, error)

Indexes shows the indexes on a table.

func (*Session) MigrateDown added in v0.26.0

func (s *Session) MigrateDown(dir string) (string, error)

MigrateDown rolls back the most recent migration.

func (*Session) MigrateStatus added in v0.26.0

func (s *Session) MigrateStatus(dir string) ([]MigrationStatus, error)

MigrateStatus returns a list of all migrations with their applied status.

func (*Session) MigrateUp added in v0.26.0

func (s *Session) MigrateUp(dir string) ([]string, error)

MigrateUp runs all pending migrations (not yet applied) in order. It uses a version tracking table `_tinker_migrations` to track applied versions.

func (*Session) ModernCLIAvailable added in v0.17.0

func (s *Session) ModernCLIAvailable() string

ModernCLIAvailable returns the modern CLI name for the current driver (even if not installed), used for hint messages.

func (*Session) Ping added in v0.22.0

func (s *Session) Ping() error

Ping tests database connectivity. Returns nil on success.

func (*Session) Schema added in v0.22.0

func (s *Session) Schema(table string) (string, error)

Schema returns the CREATE TABLE statement for a table (with syntax highlighting).

func (*Session) Seed added in v0.26.0

func (s *Session) Seed(path string) error

Seed executes SQL seed files against the database. It reads all .sql files from the given directory (or a single file), splits them by semicolons, and executes each statement.

func (*Session) Size added in v0.22.0

func (s *Session) Size() (string, error)

Size returns row counts for all tables.

func (*Session) Tables

func (s *Session) Tables() (string, error)

Tables lists all tables in the database using safe parameterized queries when a native connection is available, falling back to CLI otherwise.

Jump to

Keyboard shortcuts

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