dbconn

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 12 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeConnectionParam

func EscapeConnectionParam(param string) string

func MustSelectInt added in v1.0.13

func MustSelectInt(connection *DBConn, query string, whichConn ...int) int

* The below are convenience functions for selecting one or more ints that may * be NULL or may not exist, with the same functionality (and the same rationale) * as SelectString and SelectStringSlice; see the comments for those functions, * above, for more details.

func MustSelectIntSlice added in v1.0.13

func MustSelectIntSlice(connection *DBConn, query string, whichConn ...int) []int

func MustSelectString

func MustSelectString(connection *DBConn, query string, whichConn ...int) string

* This is a convenience function for Select() when we're selecting a single * string that may be NULL or not exist. We can't use Get() because that * expects exactly one string and will panic if no rows are returned, even if * using a sql.NullString. * * SelectString calls SelectStringSlice and returns the first value instead of * calling QueryRowx because that function doesn't indicate if there were more * rows available to be returned, and we don't want to silently ignore that if * only one row was expected for a given query but multiple were returned.

func MustSelectStringSlice

func MustSelectStringSlice(connection *DBConn, query string, whichConn ...int) []string

* This is a convenience function for Select() when we're selecting a single * column of strings that may be NULL. Select requires defining a struct for * each call, and this function uses the underlying sql functions instead of * sqlx functions to avoid needing to "SELECT [column] AS [struct field]" with * a generic struct or the like. * * It also gives a nicer error message in the event that a query is called with * multiple columns, where using a generic struct gives an opaque "missing * destination name" error.

func SelectInt added in v1.0.13

func SelectInt(connection *DBConn, query string, whichConn ...int) (int, error)

func SelectIntSlice added in v1.0.13

func SelectIntSlice(connection *DBConn, query string, whichConn ...int) ([]int, error)

func SelectString

func SelectString(connection *DBConn, query string, whichConn ...int) (string, error)

func SelectStringSlice

func SelectStringSlice(connection *DBConn, query string, whichConn ...int) ([]string, error)

func StringToSemVerRange

func StringToSemVerRange(versionStr string) semver.Range

Types

type DBConn

type DBConn struct {
	ConnPool []*sqlx.DB
	NumConns int
	Driver   DBDriver
	User     string
	DBName   string
	Host     string
	Port     int
	Tx       []*sqlx.Tx
	Version  GPDBVersion
}

* While the sqlx.DB struct (and indirectly the sql.DB struct) maintains its own * connection pool, there is no guarantee of session-level consistency between * queries and we require that level of control in some cases. Also, while * sql.Conn is a struct that represents a single session, there is no * sqlx.Conn equivalent we could use. * * Thus, DBConn maintains its own connection pool of sqlx.DBs (all set to have * exactly one database connection each) in an array, such that callers can * create NumConns goroutines and assign each an index from 0 to NumConns to * guarantee that each goroutine gets its own connection that exhibits single- * session behavior. The Exec, Select, and Get functions are set up to default * to the first connection (index 0), so the DBConn will still exhibit session- * like behavior if no connection is specified, and other functions that want to * execute in serial should pass in a 0 wherever a connection number is needed.

func NewDBConn

func NewDBConn(dbname, username, host string, port int) *DBConn

func NewDBConnFromEnvironment

func NewDBConnFromEnvironment(dbname string) *DBConn

func (*DBConn) Begin

func (dbconn *DBConn) Begin(whichConn ...int) error

func (*DBConn) Close

func (dbconn *DBConn) Close()

func (*DBConn) Commit

func (dbconn *DBConn) Commit(whichConn ...int) error

func (*DBConn) Connect

func (dbconn *DBConn) Connect(numConns int, utilityMode ...bool) error

func (*DBConn) ConnectInUtilityMode added in v1.0.7

func (dbconn *DBConn) ConnectInUtilityMode(numConns int) error

func (*DBConn) Exec

func (dbconn *DBConn) Exec(query string, whichConn ...int) (sql.Result, error)

func (*DBConn) ExecContext added in v1.0.2

func (dbconn *DBConn) ExecContext(queryContext context.Context, query string, whichConn ...int) (sql.Result, error)

func (*DBConn) Get

func (dbconn *DBConn) Get(destination interface{}, query string, whichConn ...int) error

func (*DBConn) GetWithArgs

func (dbconn *DBConn) GetWithArgs(destination interface{}, query string, args ...interface{}) error

func (*DBConn) MustBegin

func (dbconn *DBConn) MustBegin(whichConn ...int)

func (*DBConn) MustCommit

func (dbconn *DBConn) MustCommit(whichConn ...int)

func (*DBConn) MustConnect

func (dbconn *DBConn) MustConnect(numConns int)

func (*DBConn) MustConnectInUtilityMode added in v1.0.7

func (dbconn *DBConn) MustConnectInUtilityMode(numConns int)

func (*DBConn) MustExec

func (dbconn *DBConn) MustExec(query string, whichConn ...int)

func (*DBConn) MustExecContext added in v1.0.2

func (dbconn *DBConn) MustExecContext(queryContext context.Context, query string, whichConn ...int)

func (*DBConn) MustRollback

func (dbconn *DBConn) MustRollback(whichConn ...int)

func (*DBConn) Query

func (dbconn *DBConn) Query(query string, whichConn ...int) (*sqlx.Rows, error)

func (*DBConn) QueryWithArgs

func (dbconn *DBConn) QueryWithArgs(query string, args ...interface{}) (*sqlx.Rows, error)

func (*DBConn) Rollback

func (dbconn *DBConn) Rollback(whichConn ...int) error

func (*DBConn) Select

func (dbconn *DBConn) Select(destination interface{}, query string, whichConn ...int) error

func (*DBConn) SelectWithArgs

func (dbconn *DBConn) SelectWithArgs(destination interface{}, query string, args ...interface{}) error

func (*DBConn) ValidateConnNum

func (dbconn *DBConn) ValidateConnNum(whichConn ...int) int

* Ensure there isn't a mismatch between the connection pool size and number of * jobs, and default to using the first connection if no number is given.

type DBDriver

type DBDriver interface {
	Connect(driverName string, dataSourceName string) (*sqlx.DB, error)
}

type GPDBDriver

type GPDBDriver struct {
}

func (*GPDBDriver) Connect

func (driver *GPDBDriver) Connect(driverName string, dataSourceName string) (*sqlx.DB, error)

type GPDBVersion

type GPDBVersion struct {
	VersionString string
	SemVer        semver.Version
}

func InitializeVersion

func InitializeVersion(dbconn *DBConn) (dbversion GPDBVersion, err error)

func NewVersion

func NewVersion(versionStr string) GPDBVersion

* This constructor is intended as a convenience function for testing and * setting defaults; the dbconn.Connect function will automatically initialize * the version of the database to which it is connecting. * * The versionStr argument here should be a semantic version in the form X.Y.Z, * not a GPDB version string like the one returned by "SELECT version()". If * an invalid semantic version is passed, that is considered programmer error * and the function will panic.

func (GPDBVersion) AtLeast

func (dbversion GPDBVersion) AtLeast(targetVersion string) bool

func (GPDBVersion) Before

func (dbversion GPDBVersion) Before(targetVersion string) bool

func (GPDBVersion) Is

func (dbversion GPDBVersion) Is(targetVersion string) bool

Jump to

Keyboard shortcuts

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