jameshartig commented on code in PR #1855: URL: https://github.com/apache/cassandra-gocql-driver/pull/1855#discussion_r2026277749
########## helpers.go: ########## @@ -26,187 +26,51 @@ package gocql import ( "fmt" - "math/big" "net" "reflect" "strings" - "time" - - "gopkg.in/inf.v0" ) +// RowData contains the column names and pointers to the default values for each +// column type RowData struct { Columns []string Values []interface{} } -func goType(t TypeInfo) (reflect.Type, error) { - switch t.Type() { - case TypeVarchar, TypeAscii, TypeInet, TypeText: - return reflect.TypeOf(*new(string)), nil - case TypeBigInt, TypeCounter: - return reflect.TypeOf(*new(int64)), nil - case TypeTime: - return reflect.TypeOf(*new(time.Duration)), nil - case TypeTimestamp: - return reflect.TypeOf(*new(time.Time)), nil - case TypeBlob: - return reflect.TypeOf(*new([]byte)), nil - case TypeBoolean: - return reflect.TypeOf(*new(bool)), nil - case TypeFloat: - return reflect.TypeOf(*new(float32)), nil - case TypeDouble: - return reflect.TypeOf(*new(float64)), nil - case TypeInt: - return reflect.TypeOf(*new(int)), nil - case TypeSmallInt: - return reflect.TypeOf(*new(int16)), nil - case TypeTinyInt: - return reflect.TypeOf(*new(int8)), nil - case TypeDecimal: - return reflect.TypeOf(*new(*inf.Dec)), nil - case TypeUUID, TypeTimeUUID: - return reflect.TypeOf(*new(UUID)), nil - case TypeList, TypeSet: - elemType, err := goType(t.(CollectionType).Elem) - if err != nil { - return nil, err - } - return reflect.SliceOf(elemType), nil - case TypeMap: - keyType, err := goType(t.(CollectionType).Key) - if err != nil { - return nil, err - } - valueType, err := goType(t.(CollectionType).Elem) - if err != nil { - return nil, err - } - return reflect.MapOf(keyType, valueType), nil - case TypeVarint: - return reflect.TypeOf(*new(*big.Int)), nil - case TypeTuple: - // what can we do here? all there is to do is to make a list of interface{} - tuple := t.(TupleTypeInfo) - return reflect.TypeOf(make([]interface{}, len(tuple.Elems))), nil - case TypeUDT: - return reflect.TypeOf(make(map[string]interface{})), nil - case TypeDate: - return reflect.TypeOf(*new(time.Time)), nil - case TypeDuration: - return reflect.TypeOf(*new(Duration)), nil - default: - return nil, fmt.Errorf("cannot create Go type for unknown CQL type %s", t) - } -} - func dereference(i interface{}) interface{} { return reflect.Indirect(reflect.ValueOf(i)).Interface() } -func getCassandraBaseType(name string) Type { - switch name { - case "ascii": - return TypeAscii - case "bigint": - return TypeBigInt - case "blob": - return TypeBlob - case "boolean": - return TypeBoolean - case "counter": - return TypeCounter - case "date": - return TypeDate - case "decimal": - return TypeDecimal - case "double": - return TypeDouble - case "duration": - return TypeDuration - case "float": - return TypeFloat - case "int": - return TypeInt - case "smallint": - return TypeSmallInt - case "tinyint": - return TypeTinyInt - case "time": - return TypeTime - case "timestamp": - return TypeTimestamp - case "uuid": - return TypeUUID - case "varchar": - return TypeVarchar - case "text": - return TypeText - case "varint": - return TypeVarint - case "timeuuid": - return TypeTimeUUID - case "inet": - return TypeInet - case "MapType": - return TypeMap - case "ListType": - return TypeList - case "SetType": - return TypeSet - case "TupleType": - return TypeTuple - default: - return TypeCustom +// TODO: move to types.go Review Comment: I did end up moving some of these over if I significantly rewrote them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org