Releases: go-goyave/filter
v0.6.0
Type safety
Added type-safety. The operators now generate valid SQL matching the column's data type. The data type is determined by the new struct tag fieldType
. If not provided, the type will be determined from GORM's data type. If GORM's data type is a custom type or a type that is not directly supported by this library, the type will fall back to -
(unsupported).
See the updated README for more details.
Breaking change
This change breaks custom operators: the function signature changed.
//Before
func(tx *gorm.DB, filter *filter.Filter, column string, dataType schema.DataType) *gorm.DB
// After
func(tx *gorm.DB, f *filter.Filter, column string, dataType filter.DataType) *gorm.DB
You may need to update your models by adding the new fieldType
struct tag on non-native types (such as arrays and enum types). Structures implementing driver.Valuer
should work without needing for a change.
type MyModel struct {
ID uint
SomeArray []string `gorm:"type:VARCHAR(255)[]" filterType:"text[]"`
SomeEnum MyCustomEnum `gorm:"type:my_custom_enum" filterType:"enum"`
}
Fields having a custom database type set (gorm:"type:DOUBLE PRECISION"
for example) should work too as the type detection is based on GORMDataType
and not on the actual DataType
.
Types from the guregu/null
library should work without having to add the fieldType
tag since they implement driver.Valuer
.
You may also need to update computed columns that would return a type that doesn't exactly match the struct field. This is common when working with JSON nested fields. Database engines usually always return text types from JSON operations, which is incompatible with numbers.
// This example is compatible with PostgreSQL.
// JSON processing may be different if you are using another database engine.
type MyModel struct {
ID uint
JSONColumn datatypes.JSON
SomeJSONField null.Int `gorm:"->;-:migration" computed:"(~~~ct~~~.json_column->>'fieldName')::int"`
}
v0.5.3
- Added support for computed columns in manual joins. This avoids "column doesn't exist" error when working with computed columns in relations.
- Fixed some issues related to selected columns when using manual joins.
v0.5.2
- Updated GORM.
- Fixed some issues with the latest version of GORM.
v0.5.1
- Fixed automatic column selection not working in joins. Before the fix, only the ID and foreign keys were automatically selected if no field were provided by the client in the "join".
v0.5.0
- Added
ScopeUnpaginated()
to make it possible to use the library without paginating.
v0.4.0
v0.3.7
- Fixed
IsFinal
not taken into account in filters and sorts.
v0.3.6
- Handle
AS
keyword in the raw join duplication prevention
v0.3.5
- Auto-join injector now also checks raw joins in
Statement.Joins
to avoid duplicate joins.
v0.3.4
- Fixed user-defined joins not selecting relation fields