Documentation
¶
Overview ¶
Package dbconn opens read-only, time-limited connections to MySQL and MariaDB servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Describe ¶
Describe renders the connection target without the password, e.g. shop_ro@db.internal:3306/shop.
func ErrorText ¶ added in v0.3.0
ErrorText describes a failed statement without quoting the server's message, which can repeat bound arguments or bytes from a row. Reports and warnings use it for every statement that reads keys or values.
func IsTimeout ¶ added in v0.3.0
IsTimeout reports whether a statement was stopped by the client or server time limit.
func ParseDSN ¶
ParseDSN reads a connection string in either of these forms:
mysql://user:pass@host:3306/dbname?tls=true user:pass@tcp(host:3306)/dbname?tls=true
The URL form also accepts ?socket=/path/to/mysqld.sock. When the DSN has no password, password (usually from PRODMASK_PASSWORD) is used instead.
func WritePrivileges ¶
WritePrivileges reads SHOW GRANTS output and returns the privileges that would let the user change the given database.
Types ¶
type Session ¶
type Session struct {
DB *sql.DB
Server model.ServerInfo
Database string
Timeout time.Duration
// ServerTimeout reports whether the server enforces Timeout itself
// (max_statement_time or max_execution_time). Without it, a statement
// the client gives up on keeps running on the server.
ServerTimeout bool
Warnings []string
}
Session is a pool of exactly one connection to the scanned database. Every connection in it is read-only, gives up waiting for metadata locks after a few seconds, and has a server-side statement timeout. Statements run one at a time, and autocommit is on, so no lock or snapshot outlives a statement. When a timeout kills the connection, database/sql opens a new one with the same settings.