Display timestamp fields with format RFC3339Nano

This commit is contained in:
Travis Turner 2023-03-02 22:49:44 -06:00
parent 599205ae15
commit c6e82bca77
No known key found for this signature in database
GPG key ID: 3FB5CF5C97A37B30

View file

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"io"
"time"
featurebase "github.com/featurebasedb/featurebase/v3"
"github.com/jedib0t/go-pretty/table"
@ -87,11 +88,20 @@ func writeTable(r *featurebase.WireQueryResponse, format *writeOptions, qOut io.
t.AppendHeader(schemaToRow(r.Schema))
}
for _, row := range r.Data {
// If the value is nil, replace it with a null string; go-pretty doesn't
// expect nil pointers in the data values.
// Loop through all the colums of each row and modify any based on
// type.
//
// If the value is nil, replace it with a null string; go-pretty
// doesn't expect nil pointers in the data values.
//
// If the value is a time.Time, we want to print it using
// RFC3339Nano to be consistent with everything else.
for i := range row {
if row[i] == nil {
switch v := row[i].(type) {
case nil:
row[i] = nullValue
case time.Time:
row[i] = v.Format(time.RFC3339Nano)
}
}
t.AppendRow(table.Row(row))