MCPcopy
hub / github.com/mathaou/termdbms / GetStringRepresentationOfInterface

Function GetStringRepresentationOfInterface

viewer/util.go:80–99  ·  view source on GitHub ↗
(val interface{})

Source from the content-addressed store, hash-verified

78}
79
80func GetStringRepresentationOfInterface(val interface{}) string {
81 if str, ok := val.(string); ok {
82 return str
83 } else if i, ok := val.(int64); ok { // these default to int64 so not sure how this would affect 32 bit systems TODO
84 return fmt.Sprintf("%d", i)
85 } else if i, ok := val.(int32); ok { // these default to int32 so not sure how this would affect 32 bit systems TODO
86 return fmt.Sprintf("%d", i)
87 } else if i, ok := val.(float64); ok {
88 return fmt.Sprintf("%.2f", i)
89 } else if i, ok := val.(float32); ok {
90 return fmt.Sprintf("%.2f", i)
91 } else if t, ok := val.(time.Time); ok {
92 str := t.String()
93 return str
94 } else if val == nil {
95 return "NULL"
96 }
97
98 return ""
99}
100
101func WriteCSV(m *TuiModel) { // basically display table but without any styling
102 if m.QueryData == nil || m.QueryResult == nil {

Callers 4

initFunction · 0.85
EditEnterFunction · 0.85
WriteCSVFunction · 0.85
DisplayTableFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected