Skip to content

Commit

Permalink
fix order by specific number type
Browse files Browse the repository at this point in the history
  • Loading branch information
baxiry committed Jul 5, 2024
1 parent 4a3f2d7 commit 9107a3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions engine/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions engine/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 9107a3e

Please sign in to comment.