Skip to content

Releases: go-goyave/filter

v0.6.0

12 Apr 14:56
60c7424
Compare
Choose a tag to compare

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

03 Nov 14:52
1402f6e
Compare
Choose a tag to compare
  • 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

02 Nov 16:26
901baf2
Compare
Choose a tag to compare
  • Updated GORM.
  • Fixed some issues with the latest version of GORM.

v0.5.1

19 Oct 07:53
e3955fc
Compare
Choose a tag to compare
  • 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

19 Sep 14:36
e8601ee
Compare
Choose a tag to compare
  • Added ScopeUnpaginated() to make it possible to use the library without paginating.

v0.4.0

29 Aug 12:05
0f76542
Compare
Choose a tag to compare
  • Added support for computed columns
  • Added the ability to change the separator used for query parsing #5

v0.3.7

02 Aug 08:42
e305b7f
Compare
Choose a tag to compare
  • Fixed IsFinal not taken into account in filters and sorts.

v0.3.6

02 Aug 07:55
70465fd
Compare
Choose a tag to compare
  • Handle AS keyword in the raw join duplication prevention

v0.3.5

01 Aug 15:33
a4fb56e
Compare
Choose a tag to compare
  • Auto-join injector now also checks raw joins in Statement.Joins to avoid duplicate joins.

v0.3.4

20 Jun 14:53
b21cc31
Compare
Choose a tag to compare
  • Fixed user-defined joins not selecting relation fields