-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresult.go
More file actions
60 lines (54 loc) · 1.28 KB
/
result.go
File metadata and controls
60 lines (54 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package duckql
import (
"fmt"
"reflect"
"strings"
"time"
)
type ResultRows []ResultRow
func (r *ResultRows) String() string {
var s strings.Builder
for i, row := range *r {
if i > 0 {
s.WriteString("\n")
}
s.WriteString(row.String())
}
return s.String()
}
type ResultRow []ResultValue
func (r *ResultRow) String() string {
var s strings.Builder
for i, v := range *r {
if i > 0 {
s.WriteString("|")
}
switch v.Value.Kind() {
case reflect.Bool:
var b int
if v.Value.Bool() {
b = 1
}
s.WriteString(fmt.Sprintf("%d", b))
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
s.WriteString(fmt.Sprintf("%d", v.Value.Int()))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
s.WriteString(fmt.Sprintf("%d", v.Value.Uint()))
case reflect.Float32, reflect.Float64:
s.WriteString(fmt.Sprintf("%f", v.Value.Float()))
case reflect.String:
s.WriteString(fmt.Sprintf("%s", v.Value.String()))
case reflect.Struct:
if v.Value.Type().Name() == "Time" {
s.WriteString(fmt.Sprintf("%d", v.Value.Interface().(time.Time).Unix()))
}
default:
s.WriteString(fmt.Sprintf("%v", v.Value.Interface()))
}
}
return s.String()
}
type ResultValue struct {
Name string
Value reflect.Value
}