Compare commits

...

2 Commits

Author SHA1 Message Date
Hein
7f5b851669 Empty sort appended bug fix
Some checks failed
Tests / Build (push) Has been cancelled
Tests / Run Tests (1.23.x) (push) Has been cancelled
Tests / Run Tests (1.24.x) (push) Has been cancelled
Tests / Lint Code (push) Has been cancelled
2025-11-11 17:16:59 +02:00
Hein
f0e26b1c0d Fixed and refactored reflection.Len 2025-11-11 17:07:44 +02:00
2 changed files with 14 additions and 2 deletions

View File

@@ -1,9 +1,15 @@
package common package reflection
import "reflect" import "reflect"
func Len(v any) int { func Len(v any) int {
val := reflect.ValueOf(v) val := reflect.ValueOf(v)
valKind := val.Kind()
if valKind == reflect.Ptr {
val = val.Elem()
}
switch val.Kind() { switch val.Kind() {
case reflect.Slice, reflect.Array, reflect.Map, reflect.String, reflect.Chan: case reflect.Slice, reflect.Array, reflect.Map, reflect.String, reflect.Chan:
return val.Len() return val.Len()

View File

@@ -293,6 +293,9 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
logger.Debug("Applying expand: %s", expand.Relation) logger.Debug("Applying expand: %s", expand.Relation)
sorts := make([]common.SortOption, 0) sorts := make([]common.SortOption, 0)
for _, s := range strings.Split(expand.Sort, ",") { for _, s := range strings.Split(expand.Sort, ",") {
if s == "" {
continue
}
dir := "ASC" dir := "ASC"
if strings.HasPrefix(s, "-") || strings.HasSuffix(strings.ToUpper(s), " DESC") { if strings.HasPrefix(s, "-") || strings.HasSuffix(strings.ToUpper(s), " DESC") {
dir = "DESC" dir = "DESC"
@@ -523,7 +526,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st
metadata := &common.Metadata{ metadata := &common.Metadata{
Total: int64(total), Total: int64(total),
Count: int64(common.Len(modelPtr)), Count: int64(reflection.Len(modelPtr)),
Filtered: int64(total), Filtered: int64(total),
Limit: limit, Limit: limit,
Offset: offset, Offset: offset,
@@ -1531,6 +1534,9 @@ func (h *Handler) FetchRowNumber(ctx context.Context, tableName string, pkName s
if len(options.Sort) > 0 { if len(options.Sort) > 0 {
sortParts := make([]string, 0, len(options.Sort)) sortParts := make([]string, 0, len(options.Sort))
for _, sort := range options.Sort { for _, sort := range options.Sort {
if sort.Column == "" {
continue
}
direction := "ASC" direction := "ASC"
if strings.EqualFold(sort.Direction, "desc") { if strings.EqualFold(sort.Direction, "desc") {
direction = "DESC" direction = "DESC"