Skip to content

Commit

Permalink
Add support for yugabyte-specific jsonb column
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshartig committed Feb 13, 2023
1 parent e557c08 commit c4804bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func goType(t TypeInfo) (reflect.Type, error) {
return reflect.TypeOf(*new(time.Duration)), nil
case TypeTimestamp:
return reflect.TypeOf(*new(time.Time)), nil
case TypeBlob:
case TypeBlob, TypeJsonb:
return reflect.TypeOf(*new([]byte)), nil
case TypeBoolean:
return reflect.TypeOf(*new(bool)), nil
Expand Down Expand Up @@ -137,6 +137,8 @@ func getCassandraBaseType(name string) Type {
return TypeSet
case "TupleType":
return TypeTuple
case "jsonb":
return TypeJsonb
default:
return TypeCustom
}
Expand Down
7 changes: 5 additions & 2 deletions marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Marshal(info TypeInfo, value interface{}) ([]byte, error) {
}

switch info.Type() {
case TypeVarchar, TypeAscii, TypeBlob, TypeText:
case TypeVarchar, TypeAscii, TypeBlob, TypeText, TypeJsonb:
return marshalVarchar(info, value)
case TypeBoolean:
return marshalBool(info, value)
Expand Down Expand Up @@ -212,7 +212,7 @@ func Unmarshal(info TypeInfo, data []byte, value interface{}) error {
}

switch info.Type() {
case TypeVarchar, TypeAscii, TypeBlob, TypeText:
case TypeVarchar, TypeAscii, TypeBlob, TypeText, TypeJsonb:
return unmarshalVarchar(info, data, value)
case TypeBoolean:
return unmarshalBool(info, data, value)
Expand Down Expand Up @@ -2615,6 +2615,7 @@ const (
TypeSet Type = 0x0022
TypeUDT Type = 0x0030
TypeTuple Type = 0x0031
TypeJsonb Type = 0x0080 // Yugabyte YCQL JSONB
)

// String returns the name of the identifier.
Expand Down Expand Up @@ -2672,6 +2673,8 @@ func (t Type) String() string {
return "varint"
case TypeTuple:
return "tuple"
case TypeJsonb:
return "jsonb"
default:
return fmt.Sprintf("unknown_type_%d", t)
}
Expand Down

0 comments on commit c4804bb

Please sign in to comment.