github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/query/queryresult/column_def.go (about)

     1  package queryresult
     2  
     3  import "reflect"
     4  
     5  // ColumnDef is a struct used to store column information from query results
     6  type ColumnDef struct {
     7  	Name     string `json:"name"`
     8  	DataType string `json:"data_type"`
     9  	isScalar *bool
    10  }
    11  
    12  // IsScalar checks if the given value is a scalar value
    13  // it also mutates the containing ColumnDef so that it doesn't have to reflect
    14  // for all values in a column
    15  func (c *ColumnDef) IsScalar(v any) bool {
    16  	if c.isScalar == nil {
    17  		var scalar bool
    18  		switch reflect.ValueOf(v).Kind() {
    19  		case reflect.Array, reflect.Map, reflect.Slice, reflect.Struct:
    20  			scalar = false
    21  		default:
    22  			scalar = true
    23  		}
    24  		c.isScalar = &scalar
    25  	}
    26  	return *c.isScalar
    27  }