mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-10-13 16:56:28 +00:00
Adds a SetNullAsZero handler option: on by default in restheadspec (for x-fieldfilter only), off by default in resolvespec. When enabled, an eq filter of 0 on a numeric column renders (col = 0 OR col IS NULL).
40 lines
872 B
Go
40 lines
872 B
Go
package common
|
|
|
|
import "github.com/bitechdev/ResolveSpec/pkg/reflection"
|
|
|
|
// IsNumericZeroFilter reports whether value is a numeric zero compared against
|
|
// a numeric column of model. Used by the "null as zero" option, which turns
|
|
// col = 0 into (col = 0 OR col IS NULL).
|
|
func IsNumericZeroFilter(model interface{}, column string, value interface{}) bool {
|
|
if model == nil || !reflection.IsNumericType(reflection.GetColumnTypeFromModel(model, column)) {
|
|
return false
|
|
}
|
|
switch v := value.(type) {
|
|
case int:
|
|
return v == 0
|
|
case int8:
|
|
return v == 0
|
|
case int16:
|
|
return v == 0
|
|
case int32:
|
|
return v == 0
|
|
case int64:
|
|
return v == 0
|
|
case uint:
|
|
return v == 0
|
|
case uint8:
|
|
return v == 0
|
|
case uint16:
|
|
return v == 0
|
|
case uint32:
|
|
return v == 0
|
|
case uint64:
|
|
return v == 0
|
|
case float32:
|
|
return v == 0
|
|
case float64:
|
|
return v == 0
|
|
}
|
|
return false
|
|
}
|