Rene Nochebuena 9d8762458c feat(config): expose charset, loc, and parseTime as configurable DSN parameters
- add Config.Charset (MYSQL_CHARSET, default "utf8mb4"): connection character set
  sent as SET NAMES during handshake; previously hardcoded
- add Config.Loc (MYSQL_LOC, default "UTC"): IANA timezone for time.Time ↔
  DATE/DATETIME conversion; previously hardcoded
- add Config.ParseTime (MYSQL_PARSE_TIME, default "true"): driver-level DATE/DATETIME
  → time.Time mapping; valid values "true"/"false"; previously hardcoded
- update DSN() to derive parameters from Config fields with empty-means-default
  semantics; existing Config literals produce identical DSN output (backward compatible)
- remove unused url.URL construction from DSN(); params now built directly via url.Values
- document collation DSN limitation in Config godoc, CLAUDE.md, RELEASE.md, CHANGELOG.md:
  go-sql-driver v1.8.x uses 1-byte handshake collation IDs (max 255); MariaDB 11.4+
  collations such as utf8mb4_uca1400_as_cs exceed that range — set collation at the
  database/table level in schema migrations instead
2026-03-20 14:12:24 -06:00

mysql

database/sql-backed MySQL client with launcher lifecycle and health check integration.

Install

go get code.nochebuena.dev/go/mysql

Usage

db := mysql.New(logger, cfg)
lc.Append(db)
r.Get("/health", health.NewHandler(logger, db))

Unit of Work

uow := mysql.NewUnitOfWork(logger, db)

err := uow.Do(ctx, func(ctx context.Context) error {
    exec := db.GetExecutor(ctx) // returns the active Tx
    _, err := exec.ExecContext(ctx, "INSERT INTO orders ...")
    return err
})

Error mapping

if err := db.HandleError(err); err != nil { ... }
MySQL error xerrors code
1062 (ER_DUP_ENTRY) ErrAlreadyExists
1216/1217/1451/1452 (foreign key) ErrInvalidInput
sql.ErrNoRows ErrNotFound
anything else ErrInternal

Configuration

Env var Default Description
MYSQL_HOST required Database host
MYSQL_PORT 3306 Database port
MYSQL_USER required Username
MYSQL_PASSWORD required Password
MYSQL_NAME required Database name
MYSQL_MAX_CONNS 5 Max open connections
MYSQL_MIN_CONNS 2 Max idle connections
Description
MySQL client with health check and lifecycle hooks.
Readme MIT 52 KiB
2026-03-20 14:16:15 -06:00
Languages
Go 100%