Documentation
¶
Overview ¶
This package implements database/sql/driver interface, so we can use go-mysql with database/sql
Index ¶
- func AddNamedValueChecker(nvCheckFunc ...CheckNamedValueFunc)
- func CollationOption(c *client.Conn, value string) error
- func CompressOption(c *client.Conn, value string) error
- func ReadTimeoutOption(c *client.Conn, value string) error
- func SetCustomTLSConfig(dsn string, caPem []byte, certPem []byte, keyPem []byte, ...) error
- func SetDSNOptions(customOptions map[string]DriverOption)
- func UseSslOption(c *client.Conn) error
- func UseSslSkipVerifyOption(c *client.Conn) error
- func WriteTimeoutOption(c *client.Conn, value string) error
- type CheckNamedValueFunc
- type Conn
- func (c *Conn) Begin() (sqldriver.Tx, error)
- func (c *Conn) BeginTx(ctx context.Context, opts sqldriver.TxOptions) (sqldriver.Tx, error)
- func (c *Conn) CheckNamedValue(nv *sqldriver.NamedValue) error
- func (c *Conn) Close() error
- func (c *Conn) Exec(query string, args []sqldriver.Value) (sqldriver.Result, error)
- func (c *Conn) ExecContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Result, error)
- func (c *Conn) IsValid() bool
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (sqldriver.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (sqldriver.Stmt, error)
- func (c *Conn) Query(query string, args []sqldriver.Value) (sqldriver.Rows, error)
- func (c *Conn) QueryContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Rows, error)
- type Connector
- type DriverOption
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 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
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
UseSslSkipVerifyOption sets the connection to use a tls.Config with InsecureSkipVerify set to true. Currently the same as `SetTLSConfig`.
Types ¶
type CheckNamedValueFunc ¶ added in v1.9.0
type CheckNamedValueFunc func(*sqldriver.NamedValue) error
type Conn ¶ added in v1.14.0
func (*Conn) CheckNamedValue ¶ added in v1.14.0
func (c *Conn) CheckNamedValue(nv *sqldriver.NamedValue) error
func (*Conn) ExecContext ¶ added in v1.14.0
func (*Conn) PrepareContext ¶ added in v1.14.0
type Connector ¶ added in v1.14.0
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
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.