Releases: go-pkgz/enum
Releases · go-pkgz/enum
Version 0.5.0
Breaking Changes
SQL support now requires the -sql flag (previously generated by default)
- Before: SQL interfaces were always generated
- After: SQL interfaces only generated when
-sqlflag is provided - Migration: Add
-sqlto yourgo:generatedirectives if using SQL databases
New Features
- MongoDB BSON support (
-bsonflag): Generates proper BSON marshal/unmarshal methods - YAML support (
-yamlflag): Generates yaml.v3 marshal/unmarshal methods - Conditional code generation: All database/serialization features are now opt-in
Bug Fixes
- Fixed MongoDB storage issue where enums were stored as empty documents instead of strings
- Fixed handling of negative enum values (e.g.,
PriorityNone = -1) - Fixed SQL NULL handling to use zero value when available
Improvements
- Added comprehensive integration tests with real databases (MongoDB via testcontainers, SQLite)
- Improved test coverage to 99.6%
- Added runtime verification tests
- Updated documentation and examples
Usage Examples
# Basic enum (no database support)
go run github.com/go-pkgz/enum@latest -type status -lower
# With SQL support (REQUIRED if you use SQL databases)
go run github.com/go-pkgz/enum@latest -type status -sql
# With MongoDB support
go run github.com/go-pkgz/enum@latest -type status -bson -lower
# With all features
go run github.com/go-pkgz/enum@latest -type status -sql -bson -yaml -lowerv0.4.0
Performance Improvements
- O(1) map-based parsing replacing switch statements (10x faster)
- Pre-computed Values and Names as package variables instead of functions
- Single shared enum instances to reduce memory allocation
New Features
- SQL support with driver.Valuer and sql.Scanner interfaces
- Smart SQL NULL handling (uses zero value when available, errors otherwise)
- Index() method for accessing underlying integer values
-getterflag for generating GetTypeByID functions (with validation for unique values)-lowerflag for lowercase string representation in marshaling- Preserve underlying type information (uint8, int32, etc.) in generated code
Improvements
- Preserve source declaration order (was alphabetical before)
- Character literal support ('A', '\n', '\x00', etc.)
- Enhanced error messages with specific invalid value reporting
- Better binary expression handling with iota operations
- Fixed iota increment bug (now increments per ValueSpec as Go spec requires)
- Proper handling of underscore placeholders in const blocks
- Better edge case handling (division by zero, empty blocks)
Testing & Quality
- Test coverage improved from 90.5% to 99.6%
- Comprehensive test suite for all new features
- Updated documentation with SQL examples and feature descriptions
Installation
go install github.com/go-pkgz/enum@v0.4.0Full Changelog
Release v0.3.1
What's new
- Fix handling of binary expressions with iota (fixes #14)
- Now properly handles enum definitions like
- Previously, the first constant was being skipped when using expressions like
Release v0.3.0
What's new
- Add dummy usage of enum constants to prevent linter warnings
- Improve README documentation for naming conventions and parameters
- Fix go:generate examples in README to include @latest tag
- Add Go 1.23 iterator support
- Add support to get the enum value by the constant int value
- Fix handling of repeated constant values in enum declarations
- Add support for explicit enum values instead of assuming sequential iota values
- Update dependencies
- Improve file permission handling
Version 0.2.0
What's Changed
- Fix missing strings import when generating without
-lowerflag by @codemageddon in #4 - Add support for complex type names by @codemageddon in #3
New Contributors
- @codemageddon made their first contribution in #4
Full Changelog: v0.1.3...v0.2.0
Version 0.1.0
initial release