dbconn

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 SelectString

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

func SelectStringSlice

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

Types

type DBConn

type DBConn struct {
	ConnPool []*sqlx.DB
	NumConns int
	Driver   DBDriver
	User     string
	Password string // extra, vs go-common-go-lib DBConn
	DBName   string
	Host     string
	Port     int
	Tx       []*sqlx.Tx
	Version  GPDBVersion
}

DBConn -- changed

func NewDBConn

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

func NewDBConnFromEnvironment

func NewDBConnFromEnvironment(dbname string) *DBConn

func NewDBConnWithPassword

func NewDBConnWithPassword(dbname, username, password, host string, port int) *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) error

func (*DBConn) Exec

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

func (*DBConn) ExecContext

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) MustExec

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

func (*DBConn) MustExecContext

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 DBType

type DBType int

DBType represents the type of database

const (
	Unknown DBType = iota
	GPDB           // Greenplum Database
	CBDB           // Cloudberry Database
	CBEDB          // Cloudberry Enterprise Database
	ACBDB          // Apache Cloudberry Database
	HDW            // HashData Database
	PGSQL          // PostgreSQL
)

func (DBType) String

func (t DBType) String() string

String provides string representation of DBType

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
	Type          DBType
}

GPDBVersion represents version information for a database

func InitializeVersion

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

InitializeVersion parses database version string and returns version information Version string samples for different databases:

HashData:

PostgreSQL 9.4.26 (Greenplum Database 6.20.0 build 9999) (HashData Warehouse 3.13.8 build 27594)
on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11), 64-bit compiled on Feb 10 2023 17:22:03

Cloudberry:

PostgreSQL 14.4 (Cloudberry Database 1.2.0 build commit:5b5ae3f8aa638786f01bbd08307b6474a1ba1997)
on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11), 64-bit compiled on Feb 16 2023 23:44:39

Cloudberry Enterprise:

PostgreSQL 14.4 (Cloudberry Database 1.1.5 build dev) (HashData Enterprise 1.1.5 build dev)
on aarch64-unknown-linux-gnu, compiled by gcc (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11), 64-bit compiled on Feb 13 2025 14:37:41

Apache Cloudberry:

PostgreSQL 14.4 (Apache Cloudberry 2.0.0 build commit:a071e3f8aa638786f01bbd08307b6474a1ba7890)
on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11), 64-bit compiled on Jun 10 2025 15:42:54

Greenplum:

PostgreSQL 12.12 (Greenplum Database 7.0.0 build commit:bf073b87c0bac9759631746dca1c4c895a304afb)
on x86_64-pc-linux-gnu, compiled by gcc (GCC) 10.2.1 20210130 (Red Hat 10.2.1-11), 64-bit compiled on May  6 2023 16:12:25

PostgreSQL:

PostgreSQL 12.18 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit

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) Equals

func (srcVersion GPDBVersion) Equals(destVersion GPDBVersion) bool

func (GPDBVersion) Is

func (dbversion GPDBVersion) Is(targetVersion string) bool

func (GPDBVersion) IsACBDB

func (dbversion GPDBVersion) IsACBDB() bool

func (GPDBVersion) IsCBDB

func (dbversion GPDBVersion) IsCBDB() bool

func (GPDBVersion) IsCBDBFamily

func (dbversion GPDBVersion) IsCBDBFamily() bool

func (GPDBVersion) IsCBEDB

func (dbversion GPDBVersion) IsCBEDB() bool

func (GPDBVersion) IsGPDB

func (dbversion GPDBVersion) IsGPDB() bool

func (GPDBVersion) IsHDW

func (dbversion GPDBVersion) IsHDW() bool

func (GPDBVersion) IsPGSQL

func (dbversion GPDBVersion) IsPGSQL() bool

func (*GPDBVersion) ParseVersionInfo

func (dbversion *GPDBVersion) ParseVersionInfo(versionString string)

func (GPDBVersion) StringToSemVerRange

func (dbversion GPDBVersion) StringToSemVerRange(versionStr string) semver.Range

Jump to

Keyboard shortcuts

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