Documentation
¶
Overview ¶
Package mysql connects rio to MySQL through the github.com/go-sql-driver/mysql driver.
The package is deliberately thin: it constructs handles, keeps the DSN honest about parseTime and sql_mode, and translates the driver's error numbers into rio's sentinel errors. All SQL generation lives in github.com/go-rio/rio.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New wraps an existing *sql.DB in a rio handle with the MySQL dialect and this package's error translator installed. The caller's options apply after the translator, so a rio.WithErrorTranslator among them replaces it. New performs no DSN hygiene — the *sql.DB is the caller's; make sure it was opened with parseTime=true, or time.Time columns will fail to scan, and with a sql_mode free of NO_BACKSLASH_ESCAPES and ANSI_QUOTES, or rio's placeholder rewriting can disagree with the server's lexing (see Open).
func Open ¶
Open opens a MySQL database for rio. The DSN uses the go-sql-driver format: user:password@tcp(host:port)/dbname?param=value.
rio scans DATETIME and TIMESTAMP columns into time.Time, which requires the driver option parseTime=true. Open therefore appends parseTime=true when the DSN does not mention the option, and returns an error when the DSN explicitly sets parseTime=false instead of silently overriding a choice the caller spelled out. Every other option — including loc and clientFoundRows — passes through untouched, so existing data keeps its meaning; the README explains why new applications should store UTC.
rio also rewrites ? placeholders by lexing the SQL with MySQL's default rules, which the sql_mode flags NO_BACKSLASH_ESCAPES and ANSI_QUOTES change on the server. A DSN whose sql_mode system variable enables either — directly, or through a combination mode such as ANSI — is therefore rejected with an error. Any other explicit sql_mode passes through untouched, and a DSN without one leaves the server's default alone: Open never connects, so it cannot see that default. If your server enables one of those modes globally, override sql_mode for rio's connections in the DSN — the README shows a paste-ready example.
Like database/sql, Open validates its arguments without connecting; ping the handle returned by Unwrap to verify the server is reachable.
Types ¶
This section is empty.