Releases: mibk/dali
Dali v0.5 — Argument Ergonomics
- Added support for embedded structs in query parameters, including unexported ones, aligning with behaviors in packages like encoding/json.
- Introduced support for interpolating pointers and user-defined basic types in placeholders.
- Enhanced handling for typed nil values that implement
sql/driver.Valuer. - Restricted time handling to only time.Time, excluding derived types, to ensure consistent behavior.
- Updated the minimum supported Go version to 1.20.
- Implemented various improvements in code structure, error checking, and query construction logic.
Key Enhancements in Parameter and Type Handling
One of the standout features in this release is the addition of support for embedded structs, even when unexported. In previous versions, struct handling for placeholders like ?values or ?set was limited to top-level fields. Now, dali flattens embedded structs in a manner consistent with the encoding/json package, allowing developers to use more complex, nested data structures without manual flattening. For example, if a User struct embeds an Address struct (even if Address is unexported), dali will automatically include Address fields in generated SQL clauses, deriving column names from db tags where applicable. This reduces boilerplate code and aligns dali's behavior with common Go serialization practices.
Another major addition is support for interpolating pointers in placeholders. Previously, placeholders like ? expected direct values, but v0.5.0 allows pointers to primitives or compatible types, dereferencing them automatically during interpolation. This is particularly useful in scenarios where data is passed via pointers, such as from optional fields or external APIs, streamlining query preparation without explicit checks.
User-defined basic types are now fully supported, enabling custom types based on built-ins (e.g., type MyID int64) to be used seamlessly in placeholders. This extends dali's compatibility with domain-specific types, ensuring they are treated as their underlying kinds during SQL generation. Combined with the existing support for driver.Valuer implementations, this makes dali more versatile for applications with typed domains.
Furthermore, the release adds handling for typed nil values that implement sql/driver.Valuer. In earlier versions, nil handling was basic, but now typed nils (e.g., *sql.NullString(nil)) are interpolated correctly as NULL in SQL, preserving type safety and preventing runtime errors in query execution.
Refinements and Restrictions for Reliability
To promote consistent and predictable behavior, v0.5.0 restricts time handling to the standard time.Time type, excluding any derived or aliased types. This change addresses potential inconsistencies in formatting and parsing, especially in MySQL dialects where time precision is critical. Developers using custom time types should convert them to time.Time before passing to dali queries.
Error handling has been bolstered with comprehensive checks on all escapeValue operations. Previously, some errors might have been overlooked; now, every escaping step is validated, reducing the risk of silent failures during query interpolation. This aligns with best practices for secure SQL construction, helping prevent injection vulnerabilities.
The logic for placing separators (e.g., commas in VALUES or SET clauses) has been simplified. This internal optimization reduces complexity in the codebase, potentially improving performance in multi-value operations like bulk INSERTs with ?values....
General code improvements have been applied, including refactoring for clarity and efficiency. These changes enhance maintainability without altering public APIs, ensuring a smoother experience for contributors and users alike.
Compatibility and Requirements Update
A key change in this release is the update to support Go version 1.20 as the minimum requirement. This allows dali to leverage improvements in Go's standard library, such as enhanced error handling and performance optimizations in database/sql. Users on older Go versions should upgrade to benefit from v0.5.0. Note that this may introduce breaking changes if your codebase relies on deprecated features from prior Go releases.
No major breaking changes to the public API are introduced beyond the Go version bump, maintaining backward compatibility with v0.4.0 for most use cases. However, the refined type restrictions (e.g., time.Time only) may require minor adjustments in applications using derived types.
Full Changelog: v0.4.0...v0.5.0
Dali v0.4 — Hello, Context
This tiny release adds support for context.Context. It breaks compatibility; the Execer interface is changed.
Full Changelog: v0.3.0...v0.4.0
v0.3
Changes:
- Requires at least Go 1.10
- Uses Go 1.11 Modules
- Package
dialectsrenamed todialect(alsodialect.MySQLis now a variable rather than a function) NullTimeremovedScanWholeColsrenamed toScanAllRowsomitinserttag flag renamed toselectonly- Added experimental
Marshalerinterface Preprocessorrenamed toTranslator- MySQL: Fixed time precision