db

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 14 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyCertificatesIgnoreHostname

func VerifyCertificatesIgnoreHostname(rawCerts [][]byte, caCertPool *x509.CertPool) error

Types

type Config

type Config struct {
	Type                   string `json:"type" validate:"nonzero"`
	User                   string `json:"user" validate:"nonzero"`
	Password               string `json:"password"`
	Host                   string `json:"host" validate:"nonzero"`
	Port                   uint16 `json:"port" validate:"nonzero"`
	Timeout                int    `json:"timeout" validate:"min=1"`
	DatabaseName           string `json:"database_name" validate:""`
	RequireSSL             bool   `json:"require_ssl" validate:""`
	CACert                 string `json:"ca_cert" validate:""`
	SkipHostnameValidation bool   `json:"skip_hostname_validation" validate:""`
}

func (Config) ConnectionString

func (c Config) ConnectionString() (string, error)

type ConnWrapper

type ConnWrapper struct {
	*sqlx.DB
	Monitor monitor.Monitor
}

func GetConnectionPool

func GetConnectionPool(dbConfig Config, ctx context.Context) (*ConnWrapper, error)

func NewConnectionPool

func NewConnectionPool(conf Config,
	maxOpenConnections int, maxIdleConnections int, connMaxLifetime time.Duration,
	logPrefix string, jobPrefix string, logger lager.Logger,
) (*ConnWrapper, error)

func (*ConnWrapper) Beginx

func (c *ConnWrapper) Beginx() (Transaction, error)

func (*ConnWrapper) OpenConnections

func (c *ConnWrapper) OpenConnections() int

func (*ConnWrapper) Query

func (c *ConnWrapper) Query(query string, args ...interface{}) (*sql.Rows, error)

func (*ConnWrapper) QueryRow

func (c *ConnWrapper) QueryRow(query string, args ...interface{}) *sql.Row

func (*ConnWrapper) RawConnection

func (c *ConnWrapper) RawConnection() *sqlx.DB

type MySQLAdapter

type MySQLAdapter struct{}

func (MySQLAdapter) ParseDSN

func (m MySQLAdapter) ParseDSN(dsn string) (cfg *mysql.Config, err error)

func (MySQLAdapter) RegisterTLSConfig

func (m MySQLAdapter) RegisterTLSConfig(key string, config *tls.Config) error

type MySQLConnectionStringBuilder

type MySQLConnectionStringBuilder struct {
	MySQLAdapter mySQLAdapter
}

func (*MySQLConnectionStringBuilder) Build

func (m *MySQLConnectionStringBuilder) Build(config Config) (string, error)

type RetriableConnector

type RetriableConnector struct {
	Logger        lager.Logger
	Connector     func(Config, context.Context) (*ConnWrapper, error)
	Sleeper       sleeper
	RetryInterval time.Duration
	MaxRetries    int
}

func (*RetriableConnector) GetConnectionPool

func (r *RetriableConnector) GetConnectionPool(dbConfig Config, ctx context.Context) (*ConnWrapper, error)

type RetriableError

type RetriableError struct {
	Inner error
	Msg   string
}

func (RetriableError) Error

func (r RetriableError) Error() string

type RowScanner

type RowScanner interface {
	Scan(dest ...interface{}) error
}

func NewRowScanner

func NewRowScanner(monitor monitor.Monitor, scanner RowScanner) RowScanner

type SleeperFunc

type SleeperFunc func(time.Duration)

func (SleeperFunc) Sleep

func (sf SleeperFunc) Sleep(duration time.Duration)

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	QueryRow(query string, args ...interface{}) RowScanner
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	Commit() error
	Rollback() error
	Rebind(string) string
	DriverName() string
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.
monitorfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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