driver

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 17 Imported by: 4

Documentation

Overview

This package implements database/sql/driver interface, so we can use go-mysql with database/sql

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNamedValueChecker added in v1.9.0

func AddNamedValueChecker(nvCheckFunc ...CheckNamedValueFunc)

AddNamedValueChecker sets a custom NamedValueChecker for the driver connection which allows for more control in handling Go and database types beyond the default Value types. See https://pkg.go.dev/database/sql/driver#NamedValueChecker Usage requires a full import of the driver (not by side-effects only). Also note that this function is not concurrent-safe, and should only be executed while setting up the driver before establishing any connections via `sql.Open()`.

func CollationOption added in v1.9.0

func CollationOption(c *client.Conn, value string) error

func CompressOption added in v1.9.0

func CompressOption(c *client.Conn, value string) error

func ReadTimeoutOption added in v1.9.0

func ReadTimeoutOption(c *client.Conn, value string) error

func SetCustomTLSConfig

func SetCustomTLSConfig(dsn string, caPem []byte, certPem []byte, keyPem []byte, insecureSkipVerify bool, serverName string) error

SetCustomTLSConfig sets a custom TLSConfig for the address (host:port) of the supplied DSN. It requires a full import of the driver (not by side-effects only). Example of supplying a custom CA, no client cert, no key, validating the certificate, and supplying a serverName for the validation:

driver.SetCustomTLSConfig(CaPem, make([]byte, 0), make([]byte, 0), false, "my.domain.name")

func SetDSNOptions added in v1.9.0

func SetDSNOptions(customOptions map[string]DriverOption)

SetDSNOptions sets custom options to the driver that allows modifications to the connection. It requires a full import of the driver (not by side-effects only). Example of supplying a custom option:

driver.SetDSNOptions(map[string]DriverOption{
		"my_option": func(c *client.Conn, value string) error {
			c.SetCapability(mysql.CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)
			return nil
		},
	})

func UseSslOption added in v1.9.0

func UseSslOption(c *client.Conn) error

UseSslOption sets the connection to use a tls.Config with InsecureSkipVerify set to true. Use SetTLSConfig() if you need a custom tls.Config

func UseSslSkipVerifyOption added in v1.14.0

func UseSslSkipVerifyOption(c *client.Conn) error

UseSslSkipVerifyOption sets the connection to use a tls.Config with InsecureSkipVerify set to true. Currently the same as `SetTLSConfig`.

func WriteTimeoutOption added in v1.9.0

func WriteTimeoutOption(c *client.Conn, value string) error

Types

type CheckNamedValueFunc added in v1.9.0

type CheckNamedValueFunc func(*sqldriver.NamedValue) error

type Conn added in v1.14.0

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

func (*Conn) Begin added in v1.14.0

func (c *Conn) Begin() (sqldriver.Tx, error)

func (*Conn) BeginTx added in v1.14.0

func (c *Conn) BeginTx(ctx context.Context, opts sqldriver.TxOptions) (sqldriver.Tx, error)

func (*Conn) CheckNamedValue added in v1.14.0

func (c *Conn) CheckNamedValue(nv *sqldriver.NamedValue) error

func (*Conn) Close added in v1.14.0

func (c *Conn) Close() error

func (*Conn) Exec added in v1.14.0

func (c *Conn) Exec(query string, args []sqldriver.Value) (sqldriver.Result, error)

func (*Conn) ExecContext added in v1.14.0

func (c *Conn) ExecContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Result, error)

func (*Conn) IsValid added in v1.14.0

func (c *Conn) IsValid() bool

func (*Conn) Ping added in v1.14.0

func (c *Conn) Ping(ctx context.Context) error

func (*Conn) Prepare added in v1.14.0

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

func (*Conn) PrepareContext added in v1.14.0

func (c *Conn) PrepareContext(ctx context.Context, query string) (sqldriver.Stmt, error)

func (*Conn) Query added in v1.14.0

func (c *Conn) Query(query string, args []sqldriver.Value) (sqldriver.Rows, error)

func (*Conn) QueryContext added in v1.14.0

func (c *Conn) QueryContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Rows, error)

type Connector added in v1.14.0

type Connector struct {
	Addr     string
	User     string
	Password string
	DB       string
	Params   url.Values
}

Connector implements database/sql/driver.Connector so it can be used with database/sql.OpenDB to avoid constructing a DSN string manually.

Most configuration is provided via Params, using the same option keys as the standard DSN form:

[user[:password]@]addr[/db[?param=X]]

Note: the legacy DSN form is still supported when using ParseDSN, but it cannot carry URL parameters.

func ParseDSN added in v1.14.0

func ParseDSN(dsn string) (Connector, error)

ParseDSN takes a DSN string and splits it up into struct containing addr, user, password and db. It returns an error if unable to parse.

Legacy form uses a `?` as the path separator: user:password@addr[?db] Standard form uses a `/`: user:password@addr/db?param=value

Optional URL parameters are supported in the standard DSN form. The legacy form cannot carry URL parameters.

func (Connector) Connect added in v1.14.0

func (ci Connector) Connect(ctx context.Context) (sqldriver.Conn, error)

func (Connector) Driver added in v1.14.0

func (ci Connector) Driver() sqldriver.Driver

type DriverOption added in v1.9.0

type DriverOption func(c *client.Conn, value string) error

DriverOption sets configuration on a client connection before the MySQL handshake. The value represents the query string parameter value supplied by in the DNS.

Jump to

Keyboard shortcuts

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