db

package
v0.0.0-...-f839e32 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConnectTimeout        = 10 * time.Second
	DefaultQueryTimeout          = 10 * time.Second
	DefaultExecTimeout           = 10 * time.Second
	DefaultMaxOpenConnections    = 100
	DefaultMaxIdleConnections    = 1
	DefaultConnectionMaxLifetime = 10 * time.Minute
	DefaultConnectionMaxIdleTime = 1 * time.Second
)
View Source
var (
	// ErrNilData specifies the situation with result data is nil
	ErrNilData = fmt.Errorf("ErrNilData")
	// ErrNilRows specifies the situation with result rows is nil
	ErrNilRows = fmt.Errorf("ErrNilRows")
	// ErrEmptyRows specifies the situation with result no rows available to scan from
	ErrEmptyRows = fmt.Errorf("ErrEmptyRows")
)
View Source
var (
	// ErrNilResult specifies the situation with result is nil
	ErrNilResult = fmt.Errorf("ErrNilResult")
)

Functions

This section is empty.

Types

type Connection

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

Connection is a connection to a database

func NewConnection

func NewConnection(params *ConnectionParameters) *Connection

NewConnection creates new database connection

func NewConnectionConfig

func NewConnectionConfig(driverName string, cfg interface{}) *Connection

NewConnectionConfig creates new database connection from config

func (*Connection) Close

func (c *Connection) Close() error

Close closes open connection

func (*Connection) Exec

func (c *Connection) Exec(sql string, args ...interface{}) error

Exec runs given sql query w/o response

func (*Connection) GetParams

func (c *Connection) GetParams() *ConnectionParameters

func (*Connection) Query

func (c *Connection) Query(sql string, args ...interface{}) *Result

Query runs given sql query with response as one struct which includes error (if any)

type ConnectionParameters

type ConnectionParameters struct {
	// driverName which to connect with
	DriverName string

	// username which to connect with
	Username string
	// password which to connect with
	Password string

	// hostname where to connect to
	Hostname string
	// port where to connect to
	Port int

	// database to work with
	Database string

	// Ready-to-use DSN string
	Dsn string
	// DSN string with hidden credentials. Can be used in logs, etc
	DsnHiddenCredentials string

	// ConnectTimeout specifies connect timeout [OPTIONAL]
	ConnectTimeout *time.Duration
	// QueryTimeout specifies query timeout [OPTIONAL]
	QueryTimeout *time.Duration
	// ExecTimeout specifies exec timeout [OPTIONAL]
	ExecTimeout *time.Duration

	// MaxOpenConnections specifies max number of open connections [OPTIONAL]
	MaxOpenConnections *int
	// MaxIdleConnections specifies max number of idling connections [OPTIONAL]
	MaxIdleConnections *int
	// ConnectionMaxLifeTime specifies max connection lifetime [OPTIONAL]
	ConnectionMaxLifetime *time.Duration
	// ConnectionMaxIdleTime specifies max connection idling time [OPTIONAL]
	ConnectionMaxIdleTime *time.Duration
}

ConnectionParameters specifies database connection parameters

func NewConnectionParameters

func NewConnectionParameters(driverName, username, password string, hostname string, port int, database, dsn string) *ConnectionParameters

NewConnectionParameters creates new database conenction parameters

func NewConnectionParametersConfig

func NewConnectionParametersConfig(driverName string, untyped interface{}) *ConnectionParameters

NewConnectionParametersConfig creates new database connection parameters from config

func (*ConnectionParameters) GetConnectTimeout

func (c *ConnectionParameters) GetConnectTimeout() time.Duration

func (*ConnectionParameters) GetConnectionMaxIdleTime

func (c *ConnectionParameters) GetConnectionMaxIdleTime() time.Duration

func (*ConnectionParameters) GetConnectionMaxLifetime

func (c *ConnectionParameters) GetConnectionMaxLifetime() time.Duration

func (*ConnectionParameters) GetDSN

func (c *ConnectionParameters) GetDSN() string

GetDSN gets DSN

func (*ConnectionParameters) GetDSNWithHiddenCredentials

func (c *ConnectionParameters) GetDSNWithHiddenCredentials() string

GetDSNWithHiddenCredentials gets DSN with hidden credentials. Handy for logging

func (*ConnectionParameters) GetDriverName

func (c *ConnectionParameters) GetDriverName() string

GetDriverName gets name of the driver

func (*ConnectionParameters) GetExecTimeout

func (c *ConnectionParameters) GetExecTimeout() time.Duration

func (*ConnectionParameters) GetMaxIdleConnections

func (c *ConnectionParameters) GetMaxIdleConnections() int

func (*ConnectionParameters) GetMaxOpenConnections

func (c *ConnectionParameters) GetMaxOpenConnections() int

func (*ConnectionParameters) GetQueryTimeout

func (c *ConnectionParameters) GetQueryTimeout() time.Duration

func (*ConnectionParameters) HasConnectTimeout

func (c *ConnectionParameters) HasConnectTimeout() bool

func (*ConnectionParameters) HasConnectionMaxIdleTime

func (c *ConnectionParameters) HasConnectionMaxIdleTime() bool

func (*ConnectionParameters) HasConnectionMaxLifetime

func (c *ConnectionParameters) HasConnectionMaxLifetime() bool

func (*ConnectionParameters) HasExecTimeout

func (c *ConnectionParameters) HasExecTimeout() bool

func (*ConnectionParameters) HasMaxIdleConnections

func (c *ConnectionParameters) HasMaxIdleConnections() bool

func (*ConnectionParameters) HasMaxOpenConnections

func (c *ConnectionParameters) HasMaxOpenConnections() bool

func (*ConnectionParameters) HasQueryTimeout

func (c *ConnectionParameters) HasQueryTimeout() bool

func (*ConnectionParameters) SetConnectTimeout

func (c *ConnectionParameters) SetConnectTimeout(t time.Duration)

func (*ConnectionParameters) SetConnectionMaxIdleTime

func (c *ConnectionParameters) SetConnectionMaxIdleTime(m time.Duration)

func (*ConnectionParameters) SetConnectionMaxLifetime

func (c *ConnectionParameters) SetConnectionMaxLifetime(m time.Duration)

func (*ConnectionParameters) SetDriverName

func (c *ConnectionParameters) SetDriverName(name string)

SetDriverName sets name of the driver

func (*ConnectionParameters) SetExecTimeout

func (c *ConnectionParameters) SetExecTimeout(t time.Duration)

func (*ConnectionParameters) SetMaxIdleConnections

func (c *ConnectionParameters) SetMaxIdleConnections(m int)

func (*ConnectionParameters) SetMaxOpenConnections

func (c *ConnectionParameters) SetMaxOpenConnections(m int)

func (*ConnectionParameters) SetQueryTimeout

func (c *ConnectionParameters) SetQueryTimeout(t time.Duration)

type Data

type Data struct {

	// Rows specifies rows returned from the database
	Rows *databasesql.Rows
	// contains filtered or unexported fields
}

Data describes data returned from the database

func (*Data) AllFn

func (d *Data) AllFn(extractor func(*databasesql.Rows) (interface{}, error)) (result []interface{}, err error)

func (*Data) Close

func (d *Data) Close() error

Close closes the data returned from the database

func (*Data) GetRows

func (d *Data) GetRows() *databasesql.Rows

GetRows return rows returned from the database

func (*Data) Scan

func (d *Data) Scan(dest ...interface{}) error

Scan scans from the rows into set of variables

type DataChunkTransport

type DataChunkTransport struct {
}

func NewDataChunkTransport

func NewDataChunkTransport() *DataChunkTransport

NewDataChunkTransport

func (*DataChunkTransport) Recv

func (t *DataChunkTransport) Recv() (*common.DataChunk, error)

Recv

func (*DataChunkTransport) Send

func (t *DataChunkTransport) Send(dataChunk *common.DataChunk) error

Send

type Result

type Result struct {
	// Data returned by the database
	*Data
	// Error returned by the database
	Error error
}

Result specifies result returned by the database - whihc encludes returned data and error code in case of an error

func (*Result) Close

func (r *Result) Close() error

Close closes

func (*Result) Failed

func (r *Result) Failed() bool

Failed return true in case the result is failed

func (*Result) GetError

func (r *Result) GetError() error

GetError returns error

func (*Result) GetRows

func (r *Result) GetRows() *databasesql.Rows

GetRows return rows returned from the database

func (*Result) Ok

func (r *Result) Ok() bool

Ok return true in case the result is ok

func (*Result) Scan

func (r *Result) Scan(dest ...interface{}) error

Scan scans result

func (*Result) ScanClose

func (r *Result) ScanClose(dest ...interface{}) error

ScanClose scans and closes result

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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