Skip to content

Commit

Permalink
fix db query result order
Browse files Browse the repository at this point in the history
  • Loading branch information
solaoi committed May 11, 2022
1 parent a64a9ed commit 1f2e18b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions command/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/spf13/cobra"
// valid usage.
_ "github.com/mattn/go-sqlite3"
"github.com/iancoleman/orderedmap"
)

var (
Expand Down Expand Up @@ -441,16 +441,15 @@ func contentBuilder(contents map[int]map[string]map[string]interface{}) func(req
return body{http.StatusInternalServerError, "", []apiResponse{}}
}
defer rows.Close()
dummy := []map[string]json.RawMessage{}
dummy := []*orderedmap.OrderedMap{}
errJSON := json.Unmarshal([]byte(dummyJSON), &dummy)
if errJSON != nil {
log.Fatal(errJSON)
}
keys := []string{}
for k := range dummy[0] {
for _,k := range dummy[0].Keys() {
keys = append(keys, k)
}
sort.Strings(keys)
count := len(keys)
results := []map[string]string{}
for rows.Next() {
Expand Down
1 change: 1 addition & 0 deletions command/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/eknkc/pug v0.0.0-20180224090515-607e1323ff9d
github.com/fatih/color v1.13.0
github.com/go-sql-driver/mysql v1.6.0
github.com/iancoleman/orderedmap v0.2.0
github.com/kpango/gache v1.2.7
github.com/labstack/echo-contrib v0.12.0
github.com/labstack/echo/v4 v4.7.2
Expand Down
2 changes: 2 additions & 0 deletions command/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8=
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg=
Expand Down

0 comments on commit 1f2e18b

Please sign in to comment.