All notable changes to the GORMX project will be documented in this file.
- Breaking Change: Updated all methods with
where map[any]anyparameter to support genericWhereConditiontype - Now supports both
map[any]anyand*Wheretypes for maximum flexibility - Provides compile-time type safety through Go 1.18+ type constraints
All the following methods now have generic where parameter W WhereCondition:
FindOne[T any, W WhereCondition](where W) (*T, error)FindOneAndDelete[T any, W WhereCondition](where W) (*T, error)FindOneAndUpdate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)FindOneOrCreate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)GetOrCreate[T any, W WhereCondition](where W, callback func(*T)) (*T, error)Delete[T any, W WhereCondition](where W) (err error)Exists[T any, W WhereCondition](where W) (bool, error)
- Added
WhereConditioninterface type constraint:map[any]any | *Where - Added
ToWhere[T WhereCondition](condition T) *Wherehelper function for type conversion
- Backward Compatible: Existing code using
map[any]anycontinues to work - Type Safe: Compiler checks prevent passing invalid types
- Flexible: Choose simple
map[any]anyor powerful*Wherebased on needs - Performance: Optimized to use native GORM map support for simple queries
where.go- AddedWhereConditiontype constraint andToWhereconversion functionfind_one.go,delete.go,exists.go,find_one_and_delete.go,find_one_and_update.go,find_one_or_create.go,get_or_create.go- Updated to use generic where parameterWHERE_GENERIC.md- Complete documentation on generic where supportexamples/where_generic/main.go- Basic usage examplesexamples/where_generic_all/main.go- Comprehensive examples for all updated methods
- Added
Sum[T any](field string, where *Where) (float64, error)- Calculate sum of numeric field - Added
Avg[T any](field string, where *Where) (float64, error)- Calculate average of numeric field - Added
Min[T any](field string, where *Where) (interface{}, error)- Find minimum value - Added
Max[T any](field string, where *Where) (interface{}, error)- Find maximum value - Added
CountDistinct[T any](field string, where *Where) (int64, error)- Count distinct values - Added
GroupBy[T any](fields []string, where *Where, aggregates []string) ([]GroupByResult, error)- Group by with aggregations - Added
Aggregate[T any](field string, where *Where, operations []string) (map[string]interface{}, error)- Multiple aggregate operations
- Added
GroupByResultstruct for group by query results - Added
AggregateResultstruct for aggregate query results
aggregate.go- Core aggregate query implementationaggregate_test.go- Comprehensive test suite for aggregate functionsAGGREGATE.md- Complete aggregate query documentationexamples/aggregate_example.go- Usage examples for aggregate queries
- Added
QueryBuilder[T any]- Fluent chain query builder with type safety - Added
NewQuery[T any]() *QueryBuilder[T]- Create new query builder instance
- Added
Where(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T] - Added
WhereEqual(field string, value interface{}) *QueryBuilder[T] - Added
WhereNotEqual(field string, value interface{}) *QueryBuilder[T] - Added
WhereIn(field string, values interface{}) *QueryBuilder[T] - Added
WhereNotIn(field string, values interface{}) *QueryBuilder[T] - Added
WhereLike(field string, value string) *QueryBuilder[T] - Added
WhereBetween(field string, start, end interface{}) *QueryBuilder[T] - Added
WhereRaw(sql string, args ...interface{}) *QueryBuilder[T]
- Added
Select(columns ...string) *QueryBuilder[T]- Select specific columns - Added
OrderBy(field string, desc ...bool) *QueryBuilder[T]- Order by field - Added
OrderByAsc(field string) *QueryBuilder[T]- Order ascending - Added
OrderByDesc(field string) *QueryBuilder[T]- Order descending - Added
Distinct() *QueryBuilder[T]- Select distinct records
- Added
Limit(limit int) *QueryBuilder[T]- Limit results - Added
Offset(offset int) *QueryBuilder[T]- Offset results - Added
Page(page, pageSize int) *QueryBuilder[T]- Pagination helper
- Added
Join(table, condition string, args ...interface{}) *QueryBuilder[T]- Inner join - Added
LeftJoin(table, condition string, args ...interface{}) *QueryBuilder[T]- Left join - Added
RightJoin(table, condition string, args ...interface{}) *QueryBuilder[T]- Right join - Added
Preload(associations ...string) *QueryBuilder[T]- Eager load associations
- Added
GroupBy(fields ...string) *QueryBuilder[T]- Group by fields - Added
Having(field string, value interface{}, opts ...*SetWhereOptions) *QueryBuilder[T]- Having clause
- Added
Find() ([]*T, error)- Execute and get all results - Added
First() (*T, error)- Execute and get first result - Added
Last() (*T, error)- Execute and get last result - Added
Count() (int64, error)- Execute and count - Added
Exists() (bool, error)- Check if results exist - Added
Paginate(page, pageSize int) ([]*T, int64, error)- Paginate with total count
- Added
Sum(field string) (float64, error)- Calculate sum via chain - Added
Avg(field string) (float64, error)- Calculate average via chain - Added
Min(field string) (interface{}, error)- Find minimum via chain - Added
Max(field string) (interface{}, error)- Find maximum via chain - Added
Pluck(column string, dest interface{}) error- Get column values
- Added
Create(value *T) error- Create record - Added
Save(value *T) error- Save record - Added
Update(updates map[string]interface{}) error- Update records - Added
UpdateColumn(updates map[string]interface{}) error- Update columns - Added
Delete() error- Delete records
- Added
CreateInBatches(values []*T, batchSize int) error- Batch insert - Added
FindInBatches(batchSize int, fn func(tx *gorm.DB, batch int) error) error- Process in batches - Added
Chunk(chunkSize int, callback func([]*T) error) error- Process records in chunks
- Added
Transaction(fn func(tx *QueryBuilder[T]) error) error- Execute operations in transaction
- Added
Clone() *QueryBuilder[T]- Clone query builder - Added
GetDB() *gorm.DB- Get underlying GORM DB - Added
GetTableName() string- Get table name - Added
ToSQL() (string, error)- Get SQL query string - Added
Scan(dest interface{}) error- Scan results - Added
Raw(sql string, values ...interface{}) *QueryBuilder[T]- Raw SQL query
- Added
JoinClausestruct for join operations
chain.go- Core chain query builder implementationchain_test.go- Comprehensive test suite for chain queriesCHAIN.md- Complete chain query builder documentationexamples/chain_example.go- Usage examples for chain queries
- Added
AGGREGATE.md- Comprehensive aggregate query guide - Added
CHAIN.md- Comprehensive chain query builder guide - Added
QUICK_START.md- Quick start guide for new users - Added
FEATURES.md- Complete feature list and comparison - Added
CHANGELOG.md- This changelog file - Updated
README.md- Added aggregate functions and chain query builder sections - Added usage examples in
examples/directory
- Added comprehensive test suite for aggregate functions (
aggregate_test.go) - Added comprehensive test suite for chain query builder (
chain_test.go) - All tests pass successfully (require database connection for integration tests)
- Enhanced type safety with Go generics throughout
- Improved code organization and documentation
- Better error handling and reporting
- More intuitive API design with chain query builder
- Basic CRUD operations with generics
- Where condition builder
- OrderBy builder
- Pagination support
- List operations
- Atomic operations (FindOrCreate, FindAndUpdate, etc.)
- Database connection management
- DDL operations
- User management
- HTTP integration
- Error handling utilities
- Data type support (JSON, UUID, Date)
- Model management with IoC
- Raw SQL support
- Query caching layer
- Advanced transaction management with savepoints
- Query performance monitoring and logging
- Database backup/restore utilities
- Enhanced schema migration tools
- Full-text search support
- Geospatial queries
- Time-series data support
- Advanced indexing management
- Query debugging and explain tools
- Connection pool configuration
- Read/write splitting for replicas
- Database sharding support
- Optimistic locking with version fields
- Pessimistic locking (SELECT FOR UPDATE)
- Soft delete query scopes
- Custom comparison operators (<, >, <=, >=)
- More complex where conditions (OR, nested AND/OR)
- Subquery support
- Union queries
- Window functions
- CTE (Common Table Expressions) support
where := gormx.NewWhere()
where.Set("category", "Electronics")
where.Set("in_stock", true)
orderBy := &gormx.OrderBy{}
orderBy.Set("price", true)
products, total, err := gormx.List[Product](1, 20, where, orderBy)products, total, err := gormx.NewQuery[Product]().
Where("category", "Electronics").
Where("in_stock", true).
OrderByDesc("price").
Paginate(1, 20)var result struct {
Sum float64
}
db := gormx.GetDB()
db.Model(&Product{}).
Where("category = ?", "Electronics").
Select("SUM(price) as sum").
Scan(&result)// Using standalone function
total, err := gormx.Sum[Product]("price", where)
// Or using chain query
total, err := gormx.NewQuery[Product]().
Where("category", "Electronics").
Sum("price")None in this release. All new features are additive and maintain backward compatibility.
- Core team and contributors
MIT License - See LICENSE file for details.