Encode bigints as strings
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Row []interface{}
|
||||
@@ -14,6 +16,22 @@ type Result struct {
|
||||
Rows []Row `json:"rows"`
|
||||
}
|
||||
|
||||
// Due to big int number limitations in javascript, numbers should be encoded
|
||||
// as strings so they could be properly loaded on the frontend.
|
||||
func (res *Result) PrepareBigints() {
|
||||
for i, row := range res.Rows {
|
||||
for j, col := range row {
|
||||
if col == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if reflect.TypeOf(col).Kind() == reflect.Int64 {
|
||||
res.Rows[i][j] = strconv.FormatInt(col.(int64), 10)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (res *Result) Format() []map[string]interface{} {
|
||||
var items []map[string]interface{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user