From 9107a3e27a592b6562eec9b62203e2727ad5fd39 Mon Sep 17 00:00:00 2001 From: baxiry Date: Fri, 5 Jul 2024 10:31:54 +0300 Subject: [PATCH] fix order by specific number type --- engine/aggregate.go | 6 +++--- engine/queries.go | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/engine/aggregate.go b/engine/aggregate.go index 4028808..1558f4d 100644 --- a/engine/aggregate.go +++ b/engine/aggregate.go @@ -94,7 +94,7 @@ func orderBy(param string, data []string) (list []string) { fmt.Println("type is ", typ) if typ == 2 { - list = sortInt(param, objects) + list = sortNumber(param, objects) } if typ == 3 { list = sortString(param, objects) @@ -103,14 +103,14 @@ func orderBy(param string, data []string) (list []string) { return list } -func sortInt(key string, list []gjson.Result) []string { +func sortNumber(key string, list []gjson.Result) []string { max := len(list) var tmp gjson.Result element := list[0] for max != 0 { for i := 0; i < max; i++ { - if element.Get(key).Int() < list[i].Get(key).Int() { + if element.Get(key).Num < list[i].Get(key).Num { tmp = list[i] list[i] = element element = tmp diff --git a/engine/queries.go b/engine/queries.go index 930dcfa..2858d14 100644 --- a/engine/queries.go +++ b/engine/queries.go @@ -175,7 +175,7 @@ func (db *DB) updateById(query gjson.Result) (result string) { id := query.Get("_id").String() newObj := query.Get("data").String() - coll := query.Get("c").String() + coll := query.Get("collection").String() newData := gjson.Get(`[`+oldObj+`,`+newObj+`]`, `@join`).Raw @@ -251,8 +251,9 @@ func (db *DB) findMany(query gjson.Result) (res string) { // order : order := query.Get("orderBy").String() - - listData = orderBy(order, listData) + if order != "" { + listData = orderBy(order, listData) + } // TODO aggrigate here