client

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxIdleTimeoutWithoutPing - If the connection has been idle for more than this time,
	//   then ping will be performed before use to check if it alive
	MaxIdleTimeoutWithoutPing = 10 * time.Second

	// DefaultIdleTimeout - If the connection has been idle for more than this time,
	//   we can close it (but we should remember about Pool.minAlive)
	DefaultIdleTimeout = 30 * time.Second

	// MaxNewConnectionAtOnce - If we need to create new connections,
	//   then we will create no more than this number of connections at a time.
	// This restriction will be ignored on pool initialization.
	MaxNewConnectionAtOnce = 5
)

Functions

func NewClientTLSConfig

func NewClientTLSConfig(caPem, certPem, keyPem []byte, insecureSkipVerify bool, serverName string) *tls.Config

NewClientTLSConfig: generate TLS config for client side if insecureSkipVerify is set to true, serverName will not be validated

Types

type Conn

type Conn struct {
	*packet.Conn
	// contains filtered or unexported fields
}

func Connect

func Connect(addr string, user string, password string, dbName string, options ...func(*Conn)) (*Conn, error)

Connect to a MySQL server, addr can be ip:port, or a unix socket domain like /var/sock. Accepts a series of configuration functions as a variadic argument.

func ConnectWithDialer

func ConnectWithDialer(ctx context.Context, network string, addr string, user string, password string, dbName string, dialer Dialer, options ...func(*Conn)) (*Conn, error)

Connect to a MySQL server using the given Dialer.

func (*Conn) Begin

func (c *Conn) Begin() error

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) Commit

func (c *Conn) Commit() error

func (*Conn) Execute

func (c *Conn) Execute(command string, args ...interface{}) (*Result, error)

func (*Conn) ExecuteMultiple

func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCallback) (*Result, error)

ExecuteMultiple will call perResultCallback for every result of the multiple queries that are executed.

When ExecuteMultiple is used, the connection should have the SERVER_MORE_RESULTS_EXISTS flag set to signal the server multiple queries are executed. Handling the responses is up to the implementation of perResultCallback.

Example:

queries := "SELECT 1; SELECT NOW();"
conn.ExecuteMultiple(queries, func(result *mysql.Result, err error) {
    // Use the result as you want
})

func (*Conn) ExecuteSelectStreaming

func (c *Conn) ExecuteSelectStreaming(command string, result *Result, perRowCallback SelectPerRowCallback, perResultCallback SelectPerResultCallback) error

ExecuteSelectStreaming will call perRowCallback for every row in resultset

WITHOUT saving any row data to Result.{Values/RawPkg/RowDatas} fields.

When given, perResultCallback will be called once per result

ExecuteSelectStreaming should be used only for SELECT queries with a large response resultset for memory preserving.

Example:

		var result mysql.Result
		conn.ExecuteSelectStreaming(`SELECT ... LIMIT 100500`, &result, func(row []mysql.FieldValue) error {
  		// Use the row as you want.
  		// You must not save FieldValue.AsString() value after this callback is done. Copy it if you need.
  		return nil
		}, nil)

func (*Conn) FieldList

func (c *Conn) FieldList(table string, wildcard string) ([]*Field, error)

func (*Conn) GetCharset

func (c *Conn) GetCharset() string

func (*Conn) GetConnectionID

func (c *Conn) GetConnectionID() uint32

func (*Conn) GetDB

func (c *Conn) GetDB() string

func (*Conn) HandleErrorPacket

func (c *Conn) HandleErrorPacket(data []byte) error

func (*Conn) HandleOKPacket

func (c *Conn) HandleOKPacket(data []byte) *Result

func (*Conn) IsAutoCommit

func (c *Conn) IsAutoCommit() bool

func (*Conn) IsInTransaction

func (c *Conn) IsInTransaction() bool

func (*Conn) Ping

func (c *Conn) Ping() error

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (*Stmt, error)

func (*Conn) ReadOKPacket

func (c *Conn) ReadOKPacket() (*Result, error)

func (*Conn) Rollback

func (c *Conn) Rollback() error

func (*Conn) SetAutoCommit

func (c *Conn) SetAutoCommit() error

func (*Conn) SetCapability

func (c *Conn) SetCapability(cap uint32)

SetCapability enables the use of a specific capability

func (*Conn) SetCharset

func (c *Conn) SetCharset(charset string) error

func (*Conn) SetTLSConfig

func (c *Conn) SetTLSConfig(config *tls.Config)

SetTLSConfig: use user-specified TLS config pass to options when connect

func (*Conn) UnsetCapability

func (c *Conn) UnsetCapability(cap uint32)

UnsetCapability disables the use of a specific capability

func (*Conn) UseDB

func (c *Conn) UseDB(dbName string) error

func (*Conn) UseSSL

func (c *Conn) UseSSL(insecureSkipVerify bool)

UseSSL: use default SSL pass to options when connect

type Connection

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

type ConnectionStats

type ConnectionStats struct {
	// Uses internally
	TotalCount int

	// Only for stats
	IdleCount    int
	CreatedCount int64
}

type Dialer

type Dialer func(ctx context.Context, network, address string) (net.Conn, error)

Dialer connects to the address on the named network using the provided context.

type ExecPerResultCallback

type ExecPerResultCallback func(result *Result, err error)

This function will be called once per result from ExecuteMultiple

type LogFunc

type LogFunc func(format string, args ...interface{})

type Pool

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

func NewPool

func NewPool(
	logFunc LogFunc,
	minAlive int,
	maxAlive int,
	maxIdle int,
	addr string,
	user string,
	password string,
	dbName string,
	options ...func(conn *Conn),
) *Pool

NewPool initializes new connection pool and uses params: addr, user, password, dbName and options.

minAlive specifies the minimum number of open connections that the pool will try to maintain.
maxAlive specifies the maximum number of open connections
  (for internal reasons, may be greater by 1 inside newConnectionProducer).
maxIdle specifies the maximum number of idle connections (see DefaultIdleTimeout).

func (*Pool) DropConn

func (pool *Pool) DropConn(conn *Conn)

DropConn closes the connection without any checks

func (*Pool) GetConn

func (pool *Pool) GetConn(ctx context.Context) (*Conn, error)

GetConn returns connection from the pool or create new

func (*Pool) GetStats

func (pool *Pool) GetStats(stats *ConnectionStats)

func (*Pool) PutConn

func (pool *Pool) PutConn(conn *Conn)

PutConn returns working connection back to pool

type SelectPerResultCallback

type SelectPerResultCallback func(result *Result) error

This function will be called once per result from ExecuteSelectStreaming

type SelectPerRowCallback

type SelectPerRowCallback func(row []FieldValue) error

This function will be called for every row in resultset from ExecuteSelectStreaming.

type Stmt

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

func (*Stmt) Close

func (s *Stmt) Close() error

func (*Stmt) ColumnNum

func (s *Stmt) ColumnNum() int

func (*Stmt) Execute

func (s *Stmt) Execute(args ...interface{}) (*Result, error)

func (*Stmt) ExecuteSelectStreaming

func (s *Stmt) ExecuteSelectStreaming(result *Result, perRowCb SelectPerRowCallback, perResCb SelectPerResultCallback, args ...interface{}) error

func (*Stmt) ParamNum

func (s *Stmt) ParamNum() int

func (*Stmt) WarningsNum

func (s *Stmt) WarningsNum() int

type Timestamp

type Timestamp int64

Jump to

Keyboard shortcuts

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