Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
fix: Fix bug in ValueTypeFromString (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanschaaf authored Jul 22, 2022
1 parent 306eed0 commit 6ae324e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
36 changes: 18 additions & 18 deletions provider/schema/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,42 +133,42 @@ func (v ValueType) String() string {

// ValueTypeFromString this function is mainly used by https://github.com/cloudquery/cq-gen
func ValueTypeFromString(s string) ValueType {
switch strings.ToLower(s) {
case "bool", "TypeBool":
switch strings.TrimPrefix(strings.ToLower(s), "type") {
case "bool":
return TypeBool
case "int", "TypeInt", "bigint", "TypeBigInt", "smallint", "TypeSmallInt":
case "int", "bigint", "smallint":
return TypeBigInt
case "float", "TypeFloat":
case "float":
return TypeFloat
case "uuid", "TypeUUID":
case "uuid":
return TypeUUID
case "string", "TypeString":
case "string":
return TypeString
case "json", "TypeJSON":
case "json":
return TypeJSON
case "intarray", "TypeIntArray":
case "intarray":
return TypeIntArray
case "stringarray", "TypeStringArray":
case "stringarray":
return TypeStringArray
case "bytearray":
return TypeByteArray
case "timestamp", "TypeTimestamp":
case "timestamp":
return TypeTimestamp
case "uuidarray", "TypeUUIDArray":
case "uuidarray":
return TypeUUIDArray
case "inet", "TypeInet":
case "inet":
return TypeInet
case "inetrarray", "TypeInetArray":
case "inetrarray":
return TypeInetArray
case "macaddr", "TypeMacAddr":
case "macaddr":
return TypeMacAddr
case "macaddrarray", "TypeMacAddrArray":
case "macaddrarray":
return TypeMacAddrArray
case "cidr", "TypeCIDR":
case "cidr":
return TypeCIDR
case "cidrarray", "TypeCIDRArray":
case "cidrarray":
return TypeCIDRArray
case "invalid", "TypeInvalid":
case "invalid":
return TypeInvalid
default:
return TypeInvalid
Expand Down
3 changes: 3 additions & 0 deletions provider/schema/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func TestValueTypeFromString(t *testing.T) {
assert.Equal(t, ValueTypeFromString("JSON"), TypeJSON)
assert.Equal(t, ValueTypeFromString("bigint"), TypeBigInt)
assert.Equal(t, ValueTypeFromString("Blabla"), TypeInvalid)

assert.Equal(t, ValueTypeFromString("TypeBigInt"), TypeBigInt)
assert.Equal(t, ValueTypeFromString("TypeString"), TypeString)
}

func BenchmarkColumn_ValidateTypeInt(b *testing.B) {
Expand Down

0 comments on commit 6ae324e

Please sign in to comment.