feat: Add bucket schema management commands (#52)
* feat: update generated client to include schema-management APIs * feat: implement interfaces to decode flags and CSV * feat: implement decoders for different measurement schema column formats * feat: extend bucket CLI commands to support schema type property * feat: add CLI commands to manage measurement schema * test: add unit tests for bucket schema create, update and list commands
This commit is contained in:
35
internal/cmd/bucket_schema/csv.go
Normal file
35
internal/cmd/bucket_schema/csv.go
Normal file
@ -0,0 +1,35 @@
|
||||
package bucket_schema
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/gocarina/gocsv"
|
||||
"github.com/influxdata/influx-cli/v2/internal/api"
|
||||
)
|
||||
|
||||
type csvColumn struct {
|
||||
Name string `csv:"name"`
|
||||
Type api.ColumnSemanticType `csv:"type"`
|
||||
DataType *api.ColumnDataType `csv:"data_type,omitempty"`
|
||||
}
|
||||
|
||||
func decodeCSV(r io.Reader) ([]api.MeasurementSchemaColumn, error) {
|
||||
var cols []csvColumn
|
||||
gocsv.FailIfUnmatchedStructTags = true
|
||||
err := gocsv.Unmarshal(r, &cols)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode CSV: %w", err)
|
||||
}
|
||||
|
||||
rows := make([]api.MeasurementSchemaColumn, 0, len(cols))
|
||||
for i := range cols {
|
||||
c := &cols[i]
|
||||
rows = append(rows, api.MeasurementSchemaColumn{
|
||||
Name: c.Name,
|
||||
Type: c.Type,
|
||||
DataType: c.DataType,
|
||||
})
|
||||
}
|
||||
return rows, nil
|
||||
}
|
Reference in New Issue
Block a user