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
This commit is contained in:
2026-03-20 14:12:24 -06:00
parent d9d07bcb70
commit 9d8762458c
3 changed files with 59 additions and 9 deletions

View File

@@ -5,6 +5,24 @@ All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.9.1] - 2026-03-20
### Added
- `Config.Charset string` (`MYSQL_CHARSET`, default `"utf8mb4"`): connection character set, sent as `SET NAMES <charset>` during handshake. Previously hardcoded to `utf8mb4`.
- `Config.Loc string` (`MYSQL_LOC`, default `"UTC"`): IANA timezone name used for `time.Time``DATE`/`DATETIME` conversion. Previously hardcoded to `UTC`.
- `Config.ParseTime string` (`MYSQL_PARSE_TIME`, default `"true"`): controls driver-level `DATE`/`DATETIME``time.Time` mapping. Valid values `"true"` / `"false"`. Previously hardcoded to `true`.
### Changed
- `Config.DSN()`: now derives `charset`, `loc`, and `parseTime` from the new Config fields instead of hardcoded literals. Empty fields fall back to their respective defaults, preserving identical DSN output for callers that do not set the new fields.
- Removed unused `net/url.URL` construction from `DSN()`; the method now builds params directly with `url.Values`.
### Notes
- **Backward compatible.** Existing `Config` literals that do not set `Charset`, `Loc`, or `ParseTime` produce the same DSN as v0.9.0 (`charset=utf8mb4&loc=UTC&parseTime=true`).
- **Collation via DSN is not supported.** `go-sql-driver` v1.8.x negotiates the collation using a 1-byte handshake ID (max 255). MariaDB 11.4+ collations such as `utf8mb4_uca1400_as_cs` carry IDs > 255 and will cause a connection error if set in the DSN. Set the desired collation in schema migrations at the database/table level.
## [0.9.0] - 2026-03-18
### Added
@@ -31,4 +49,5 @@ and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.
- The module is structurally parallel to `postgres` but uses `database/sql` types throughout; the two modules are intentionally type-incompatible.
- MySQL error codes are matched by numeric constant via `MySQLError.Number`, not by string parsing, for stability across MySQL and MariaDB versions.
[0.9.1]: https://code.nochebuena.dev/go/mysql/releases/tag/v0.9.1
[0.9.0]: https://code.nochebuena.dev/go/mysql/releases/tag/v0.9.0