Skip to content

Releases: go-pkgz/enum

Version 0.5.0

02 Sep 00:08
8483a46

Choose a tag to compare

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 -sql flag is provided
  • Migration: Add -sql to your go:generate directives if using SQL databases

New Features

  • MongoDB BSON support (-bson flag): Generates proper BSON marshal/unmarshal methods
  • YAML support (-yaml flag): 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 -lower

v0.4.0

11 Aug 05:50
1834756

Choose a tag to compare

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
  • -getter flag for generating GetTypeByID functions (with validation for unique values)
  • -lower flag 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.0

Full Changelog

v0.3.1...v0.4.0

Release v0.3.1

25 Apr 20:14

Choose a tag to compare

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

25 Apr 19:59

Choose a tag to compare

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

29 Mar 19:39

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.1.3...v0.2.0

Version 0.1.0

16 Feb 21:52

Choose a tag to compare

initial release