Documentation
¶
Index ¶
- func CommitTransactionForQuerier(ctx context.Context, db DBTX) error
- func OpenDB(ctx context.Context, options ConfigOptions) (*sql.DB, error)
- func OpenDBMonitor(ctx context.Context) (*sql.DB, error)
- func OpenDBWithConfigFile(ctx context.Context, configFile string) (*sql.DB, error)
- func RollbackTransactionForQuerier(ctx context.Context, db DBTX) error
- func WithReadOnlyTransaction[Q TX](ctx context.Context, db DB[Q], fn func(ctx context.Context, q Q) error) error
- func WithTransaction[Q TX](ctx context.Context, db DB[Q], fn func(ctx context.Context, q Q) error) error
- type BaseBeginner
- type BaseQuerier
- type BaseQuerierTx
- type BaseTx
- type Config
- type ConfigOptions
- type CreateConnectorFunc
- type DB
- type DBConfig
- type DBTX
- type DatabaseMetrics
- type Driver
- type MySQLConfig
- type PostgresConfig
- type TX
- type TransactionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitTransactionForQuerier ¶
CommitTransactionForQuerier contains the shared Commit() logic from both packages
func OpenDBMonitor ¶
OpenDBMonitor opens a database connection with monitor-specific defaults This is a convenience function for Monitor package compatibility
func OpenDBWithConfigFile ¶
OpenDBWithConfigFile opens a database connection using an explicit config file path This is a convenience function for API package compatibility
func RollbackTransactionForQuerier ¶
RollbackTransactionForQuerier contains the shared Rollback() logic from both packages
Types ¶
type BaseBeginner ¶
Shared interface definitions that both packages use identically
type BaseQuerier ¶
type BaseQuerier interface {
WithTx(tx *sql.Tx) BaseQuerier
}
BaseQuerier provides basic query functionality This interface should be implemented by package-specific Queries types
type BaseQuerierTx ¶
type BaseQuerierTx interface {
BaseQuerier
Begin(ctx context.Context) (BaseQuerierTx, error)
Commit(ctx context.Context) error
Rollback(ctx context.Context) error
}
BaseQuerierTx provides transaction functionality This interface should be implemented by package-specific Queries types
type Config ¶
type Config struct {
// MySQL configuration (use this OR Postgres, not both)
MySQL *MySQLConfig `yaml:"mysql,omitempty"`
// Postgres configuration (use this OR MySQL, not both)
Postgres *PostgresConfig `yaml:"postgres,omitempty"`
// Legacy flat PostgreSQL format (deprecated, for backward compatibility only)
// If neither MySQL nor Postgres is set, these fields will be used for PostgreSQL
User string `yaml:"user,omitempty"`
Pass string `yaml:"pass,omitempty"`
Host string `yaml:"host,omitempty"`
Port uint16 `yaml:"port,omitempty"`
Name string `yaml:"name,omitempty"`
SSLMode string `yaml:"sslmode,omitempty"`
}
Config represents the database configuration structure
type ConfigOptions ¶
type ConfigOptions struct {
// ConfigFiles is a list of config file paths to search for database configuration
ConfigFiles []string
// EnablePoolMonitoring enables connection pool metrics collection
EnablePoolMonitoring bool
// PrometheusRegisterer for metrics collection. If nil, no metrics are collected.
PrometheusRegisterer prometheus.Registerer
// Connection pool settings
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
}
ConfigOptions allows customization of database opening behavior
func DefaultConfigOptions ¶
func DefaultConfigOptions() ConfigOptions
DefaultConfigOptions returns the standard configuration options used by API package
func MonitorConfigOptions ¶
func MonitorConfigOptions() ConfigOptions
MonitorConfigOptions returns configuration options optimized for Monitor package
type CreateConnectorFunc ¶
CreateConnectorFunc is a function that creates a database connector
type DBTX ¶
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
DBTX matches the interface expected by SQLC-generated code This interface is implemented by both *sql.DB and *sql.Tx
type DatabaseMetrics ¶
type DatabaseMetrics struct {
ConnectionsOpen prometheus.Gauge
ConnectionsIdle prometheus.Gauge
ConnectionsInUse prometheus.Gauge
ConnectionsWaitCount prometheus.Counter
ConnectionsWaitDuration prometheus.Histogram
// contains filtered or unexported fields
}
DatabaseMetrics holds the Prometheus metrics for database connection pool monitoring
func NewDatabaseMetrics ¶
func NewDatabaseMetrics(registerer prometheus.Registerer) *DatabaseMetrics
NewDatabaseMetrics creates a new set of database metrics and registers them
type Driver ¶
type Driver struct {
CreateConnectorFunc CreateConnectorFunc
}
Driver implements the sql/driver interface with dynamic configuration
type MySQLConfig ¶ added in v0.6.0
type MySQLConfig struct {
DSN string `yaml:"dsn" default:"" flag:"dsn" usage:"Database DSN"`
User string `yaml:"user" default:"" flag:"user"`
Pass string `yaml:"pass" default:"" flag:"pass"`
DBName string `yaml:"name,omitempty"` // Optional database name override
}
MySQLConfig represents the MySQL database configuration
type PostgresConfig ¶ added in v0.6.0
type PostgresConfig struct {
User string `yaml:"user"`
Pass string `yaml:"pass"`
Host string `yaml:"host"`
Port uint16 `yaml:"port"`
Name string `yaml:"name"`
SSLMode string `yaml:"sslmode"`
}
PostgresConfig represents the PostgreSQL database configuration