Help us shape the future of Go! Take the 2026 Go Developer Survey

helpers

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 19 Imported by: 82

Documentation

Index

Constants

View Source
const (
	MySQL    = "mysql"
	Postgres = "postgres"

	LockRow   RowLock = true
	NoLockRow RowLock = false
)
View Source
const (
	MYSQL_GROUP_CONCAT_MAX_LEN = 78888889
)

MYSQL group_concat_max_len system variable defines the length of the result returned by GROUP_CONCAT() function default value 1024 only allows 282 instance indexes to be concatenated this will allow 10_000_000 instance indexes

Variables

View Source
var (
	ErrResourceExists     = errors.New("sql-resource-exists")
	ErrDeadlock           = errors.New("sql-deadlock")
	ErrBadRequest         = errors.New("sql-bad-request")
	ErrUnrecoverableError = errors.New("sql-unrecoverable")
	ErrResourceNotFound   = errors.New("sql-resource-not-found")
)

Functions

func Connect

func Connect(
	logger lager.Logger, bbsDBParam *BBSDBParam) (*sql.DB, error)

func NewSQLHelper

func NewSQLHelper(flavor string) *sqlHelper

func QuestionMarks

func QuestionMarks(count int) string

func RebindForFlavor

func RebindForFlavor(query, flavor string) string

Types

type BBSDBParam

type BBSDBParam struct {
	DriverName                    string
	DatabaseConnectionString      string
	SqlCACertFile                 string
	SqlEnableIdentityVerification bool
	ConnectionTimeout             time.Duration
	ReadTimeout                   time.Duration
	WriteTimeout                  time.Duration
}

type ColumnList

type ColumnList []string

type ErrUnknownError

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

func (*ErrUnknownError) Error

func (e *ErrUnknownError) Error() string

type Queryable

type Queryable interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
}

type QueryableDB

type QueryableDB interface {
	Queryable
	BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
	OpenConnections() int
	WaitDuration() time.Duration
	WaitCount() int64
}

func NewMonitoredDB

func NewMonitoredDB(db *sql.DB, monitor monitor.Monitor) QueryableDB

type RowLock

type RowLock bool

type RowScanner

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

func NewRowScanner

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

type SQLAttributes

type SQLAttributes map[string]interface{}

type SQLHelper

type SQLHelper interface {
	Transact(ctx context.Context, logger lager.Logger, db QueryableDB, f func(logger lager.Logger, tx Tx) error) error
	RetryOnDeadlock(logger lager.Logger, f func() error) error
	One(ctx context.Context, logger lager.Logger, q Queryable, table string, columns ColumnList, lockRow RowLock, wheres string, whereBindings ...interface{}) RowScanner
	All(ctx context.Context, logger lager.Logger, q Queryable, table string, columns ColumnList, lockRow RowLock, wheres string, whereBindings ...interface{}) (*sql.Rows, error)
	Upsert(ctx context.Context, logger lager.Logger, q Queryable, table string, attributes SQLAttributes, wheres string, whereBindings ...interface{}) (bool, error)
	Insert(ctx context.Context, logger lager.Logger, q Queryable, table string, attributes SQLAttributes) (sql.Result, error)
	Update(ctx context.Context, logger lager.Logger, q Queryable, table string, updates SQLAttributes, wheres string, whereBindings ...interface{}) (sql.Result, error)
	Delete(ctx context.Context, logger lager.Logger, q Queryable, table string, wheres string, whereBindings ...interface{}) (sql.Result, error)
	Count(ctx context.Context, logger lager.Logger, q Queryable, table string, wheres string, whereBindings ...interface{}) (int, error)

	ConvertSQLError(err error) error
	Rebind(query string) string
}

type TimeoutConn

type TimeoutConn struct {
	net.Conn
	Rd time.Duration
	Wd time.Duration
}

Per-operation deadline wrapper

func (*TimeoutConn) Read

func (tc *TimeoutConn) Read(b []byte) (int, error)

func (*TimeoutConn) Write

func (tc *TimeoutConn) Write(b []byte) (int, error)

type Tx

type Tx interface {
	Queryable
	Commit() error
	Rollback() error
}

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