mysql

package
v0.0.0-...-bea3eb9 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const DEFAULT_MAX_CONNECTIONS = 1
View Source
const DEFAULT_MAX_IDLE = 60
View Source
const DEFAULT_MIN_CONNECTIONS = 1

Variables

This section is empty.

Functions

func NewConnection

func NewConnection(conn *sql.DB) (*connection, error)

Make a new one of these

func NewConnectionPool

func NewConnectionPool(dsn db.DSN) *connectionPool

func NewLeasedConnection

func NewLeasedConnection(pooledConnection PooledConnectionIfc, leaseKey int64) *leasedConnection

func NewLeasedConnections

func NewLeasedConnections() *leasedConnections

func NewMySQLConnectionFactory

func NewMySQLConnectionFactory() *db.DBConnectionFactory

func NewPooledConnection

func NewPooledConnection(connection ConnectionIfc, connPool ConnectionPoolIfc) (*pooledConnection, error)

func NewQuery

func NewQuery(connection ConnectionIfc, sqlQuery SQLQueryIfc) (*query, error)

Make a new one of these! Returns nil+error if there is any problem setting up the sqlQuery...!

func NewResult

func NewResult(res db.Result) *result

func NewResultSet

func NewResultSet() *resultSet

Types

type ConnectionCommonIfc

type ConnectionCommonIfc interface {
	InTransaction() bool
	Begin() error
	NewQuery(query SQLQueryIfc) (QueryIfc, error)
	Commit() error
	Rollback() error
	Exec(query SQLQueryIfc, args ...interface{}) (sql.Result, error)
	Query(query SQLQueryIfc, args ...interface{}) (*sql.Rows, error)
	QueryRow(query SQLQueryIfc, args ...interface{}) *sql.Row
}

type ConnectionIfc

type ConnectionIfc interface {
	IsConnected() bool
	ConnectionCommonIfc
}

type ConnectionPoolIfc

type ConnectionPoolIfc interface {
	// Embedded interface(s)
	startable.StartableIfc
	dep.DependencyInjectableIfc
	cfg.ConfigurableIfc

	// Our own interface
	GetConnection() (*leasedConnection, error)
	Release(leaseKey int64) error
	GetMaxIdle() int
	Close() error
}

A Connection Pool to maintain a set of one or more persistent connections to a MySQL database

func ConnectionPoolFromIfc

func ConnectionPoolFromIfc(i interface{}) (ConnectionPoolIfc, error)

type LeasedConnectionIfc

type LeasedConnectionIfc interface {
	ConnectionCommonIfc

	Release() error
}

type LeasedConnectionsIfc

type LeasedConnectionsIfc interface {
	// Public interface
	GetLeaseForConnection(connection PooledConnectionIfc) *leasedConnection
	Release(leaseKey int64) bool
	// contains filtered or unexported methods
}

type PooledConnectionIfc

type PooledConnectionIfc interface {

	// Connections
	IsConnected() bool

	// Leasing
	IsLeased() bool
	MatchesLeaseKey(leaseKey int64) bool
	Lease(leaseKey int64)
	Release() error
	Touch()
	IsExpired() bool

	ConnectionCommonIfc
}

TODO: Can we not inherit this interface from ConnectionIfc?

type QueryIfc

type QueryIfc interface {
	Run(args ...interface{}) (*result, error)
	RunReturnValue(receiver interface{}, args ...interface{}) error
	RunReturnInt(args ...interface{}) (*int, error)
	RunReturnString(args ...interface{}) (*string, error)
	RunReturnOne(args ...interface{}) (*ResultRow, error)
	RunReturnAll(args ...interface{}) (*resultSet, error)
	RunReturnSome(max int, args ...interface{}) (*resultSet, error)
}

type ResultIfc

type ResultIfc interface {
	GetLastInsertId() (*int64, error)
	GetRowsAffected() (*int64, error)
}

type ResultRow

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

Exported structure with non-exported properties to prevent consumer from accessing directly

func NewResultRow

func NewResultRow() *ResultRow

func (ResultRow) Fields

func (r ResultRow) Fields() []string

Pluck the fields out of the result and just return them so that caller can iterate with Get()

func (ResultRow) Get

func (r ResultRow) Get(field string) nullables.NullableIfc

Get the named field value as a nullable from this ResultRow Note: Defies "accept interfaces, return structs" convention to support multiple Nullable types

func (ResultRow) Has

func (r ResultRow) Has(field string) bool

func (ResultRow) MarshalJSON

func (r ResultRow) MarshalJSON() ([]byte, error)

func (*ResultRow) Set

func (r *ResultRow) Set(field string, value nullables.Nullable)

func (ResultRow) ToJson

func (r ResultRow) ToJson() (*string, error)

type ResultRowIfc

type ResultRowIfc interface {
	Get(field string) nullables.NullableIfc
	Set(field string, value nullables.Nullable)
	Has(field string) bool
	Fields() []string
	ToJson() (*string, error)
}

type ResultSetIfc

type ResultSetIfc interface {
	// Embedded interface(s)
	it.IterableIfc

	// Our own interface
	Get(rowNum int) *ResultRow
	Len() int
	IsEmpty() bool
	Add(result ResultRowIfc)
	IsFinalized() bool
	Finalize()
	ToJson() (*string, error)
}

type SQLQuery

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

func NewSQLQuery

func NewSQLQuery(query string) *SQLQuery

func (*SQLQuery) Resolve

func (r *SQLQuery) Resolve(args ...interface{}) (string, error)

Resolve this query object as a flat SQL statement ready for execution Supplied args are same as those that will be fed to a prepared statement. These can be used to hint our resolver here with macro tokens that will sub in the correct number of placeholders for prepared statements, etc.

Using Pointer Receiver because we we don't want the caller to have to dereference a pointer produced by NewSQLQuery().

type SQLQueryIfc

type SQLQueryIfc interface {
	// Resolve the query as a string or else a non-nil error
	Resolve(args ...interface{}) (string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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