Documentation
¶
Overview ¶
Package sql is a sqlx-backed SQL client with leader/follower routing, transactions, prepared statements, and optional Prometheus instrumentation. It targets MySQL, Postgres, and SQLite drivers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = sql.ErrNoRows
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command interface {
Close() error
Ping(ctx context.Context) error
In(query string, args ...interface{}) (string, []interface{}, error)
Rebind(query string) string
QueryIn(ctx context.Context, name string, query string, args ...interface{}) (*sqlx.Rows, error)
QueryRow(ctx context.Context, name string, query string, args ...interface{}) (*sqlx.Row, error)
Query(ctx context.Context, name string, query string, args ...interface{}) (*sqlx.Rows, error)
NamedQuery(ctx context.Context, name string, query string, arg interface{}) (*sqlx.Rows, error)
Prepare(ctx context.Context, name string, query string) (CommandStmt, error)
NamedExec(ctx context.Context, name string, query string, args interface{}) (sql.Result, error)
Exec(ctx context.Context, name string, query string, args ...interface{}) (sql.Result, error)
BeginTx(ctx context.Context, name string, opts TxOptions) (CommandTx, error)
Get(ctx context.Context, name string, query string, dest interface{}, args ...interface{}) error
}
type CommandStmt ¶
type CommandStmt interface {
Close() error
Select(name string, dest interface{}, args ...interface{}) error
Get(name string, dest interface{}, args ...interface{}) error
QueryRow(name string, args ...interface{}) (*sqlx.Row, error)
Query(name string, args ...interface{}) (*sqlx.Rows, error)
Exec(name string, args ...interface{}) (sql.Result, error)
}
type CommandTx ¶
type CommandTx interface {
Commit() error
Rollback()
Rebind(query string) string
Select(name string, query string, dest interface{}, args ...interface{}) error
Get(name string, query string, dest interface{}, args ...interface{}) error
QueryRow(name string, query string, args ...interface{}) (*sqlx.Row, error)
Query(name string, query string, args ...interface{}) (*sqlx.Rows, error)
Prepare(name string, query string) (CommandStmt, error)
NamedExec(name string, query string, args interface{}) (sql.Result, error)
Exec(name string, query string, args ...interface{}) (sql.Result, error)
Stmt(name string, stmt *sqlx.Stmt) CommandStmt
}
type Config ¶
type Config struct {
UseInstrument bool
LogQuery bool
Driver string
Name string
Leader ConnConfig
Follower ConnConfig
}
Config controls how Init builds the SQL client: which driver to use, connection settings for the leader and follower, whether to emit instrumentation metrics, and whether to log every query (useful in development and noisy in production).
type ConnConfig ¶
type ConnConfig struct {
Host string
Port int
DB string
User string
Password string
SSL bool
Schema string
Options ConnOptions
MockDB *sql.DB
}
ConnConfig describes a single connection. MockDB, when non-nil, is preferred over the Host/Port/DB/User/Password fields and lets tests inject a pre-built *sql.DB (for example a sqlmock or an in-memory sqlite database).
type ConnOptions ¶
ConnOptions tunes the underlying database/sql pool.
type Interface ¶
Interface is the public surface of the sql package. Leader returns the read/write Command, Follower returns the read-only Command (or the leader when no follower is configured), and Stop closes both pools at most once.
type TxOptions ¶
type TxOptions struct {
Isolation sql.IsolationLevel
ReadOnly bool
}