mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-09-15 21:02:35 +00:00
fix(restheadspec,resolvespec): stop casting SqlNull-wrapped and citext columns to TEXT in filters
reflect.Type.Kind() on spectypes.SqlNull[T] wrappers (SqlInt16/32/64, SqlFloat64, SqlBool, SqlString, and embedders like SqlTimeStamp) always reports reflect.Struct, never the wrapped T. ValidateAndAdjustFilterForColumnType treated those as "complex" columns and forced CAST(col AS TEXT) on eq/gt/lt filters, e.g. CAST(atdetail.rid_parent AS TEXT) = '90446096', which can't use the index on rid_parent. Add spectypes.UnwrapKind to see through SqlNull wrappers to the underlying Kind, and use it in GetColumnTypeFromModel so numeric/string SqlNull columns are recognized correctly and compared natively. Also stop unconditionally casting to TEXT for LIKE/ILIKE and add reflection.IsCitextColumn: citext columns are already case-insensitive, so casting them to TEXT flips to case-sensitive matching and defeats a citext index.
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/bitechdev/ResolveSpec/pkg/modelregistry"
|
||||
"github.com/bitechdev/ResolveSpec/pkg/spectypes"
|
||||
)
|
||||
|
||||
type PrimaryKeyNameProvider interface {
|
||||
@@ -728,19 +729,19 @@ func GetColumnTypeFromModel(model interface{}, colName string) reflect.Kind {
|
||||
// Parse JSON tag (format: "name,omitempty")
|
||||
parts := strings.Split(jsonTag, ",")
|
||||
if parts[0] == sourceColName {
|
||||
return field.Type.Kind()
|
||||
return spectypes.UnwrapKind(field.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// Check field name (case-insensitive)
|
||||
if strings.EqualFold(field.Name, sourceColName) {
|
||||
return field.Type.Kind()
|
||||
return spectypes.UnwrapKind(field.Type)
|
||||
}
|
||||
|
||||
// Check snake_case conversion
|
||||
snakeCaseName := ToSnakeCase(field.Name)
|
||||
if snakeCaseName == sourceColName {
|
||||
return field.Type.Kind()
|
||||
return spectypes.UnwrapKind(field.Type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user