db

package
v0.21.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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

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 uses parameterized query when possible.

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)

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 (headers + column alignment). Use this for describe, find, and any result set where readability matters.

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) 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) 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