|
5 | 5 | "fmt"
|
6 | 6 | "os"
|
7 | 7 | "strings"
|
| 8 | + "strconv" |
| 9 | + |
8 | 10 |
|
9 | 11 | "github.com/gomodule/redigo/redis"
|
10 | 12 | "github.com/olekukonko/tablewriter"
|
@@ -192,19 +194,47 @@ func (g *Graph) Query(q string) (QueryResult, error) {
|
192 | 194 | return qr, err
|
193 | 195 | }
|
194 | 196 |
|
| 197 | + // Result-set is an array of arrays. |
195 | 198 | results, err := redis.Values(r[0], nil)
|
196 | 199 | if err != nil {
|
197 | 200 | return qr, err
|
198 | 201 | }
|
199 | 202 |
|
200 |
| - qr.Results = make([][]string, len(results)) |
| 203 | + records := make([][]interface{}, len(results)) |
| 204 | + |
201 | 205 | for i, result := range results {
|
202 |
| - qr.Results[i], err = redis.Strings(result, nil) |
| 206 | + // Parse each record. |
| 207 | + records[i], err = redis.Values(result, nil) |
203 | 208 | if err != nil {
|
204 | 209 | return qr, err
|
205 | 210 | }
|
206 | 211 | }
|
207 | 212 |
|
| 213 | + // Convert each record item to string. |
| 214 | + qr.Results = make([][]string, len(records)) |
| 215 | + for i, record := range records { |
| 216 | + qr.Results[i] = make([]string, len(record)) |
| 217 | + for j, item := range record { |
| 218 | + switch item.(type) { |
| 219 | + case int64: |
| 220 | + n, err := redis.Int64(item, nil) |
| 221 | + if err != nil { |
| 222 | + return qr, err |
| 223 | + } |
| 224 | + qr.Results[i][j] = strconv.FormatInt(n, 10) |
| 225 | + break |
| 226 | + |
| 227 | + case string: |
| 228 | + qr.Results[i][j], err = redis.String(item, nil) |
| 229 | + break |
| 230 | + |
| 231 | + default: |
| 232 | + qr.Results[i][j], err = redis.String(item, nil) |
| 233 | + break |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + |
208 | 238 | qr.Statistics, err = redis.Strings(r[1], nil)
|
209 | 239 | if err != nil {
|
210 | 240 | return qr, err
|
|
0 commit comments