jameshartig commented on PR #1855:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1855#issuecomment-2569699991

   Here's an example of a JSONB type:
   
   ```go
   package mypackage
   
   import "github.com/gocql/gocql"
   
   var typeJSONB gocql.Type = 0x0080
   
   func init() {
        gocql.RegisterType(typeJSONB, "jsonb", JSONBCQLType{})
   }
   
   // JSONBTypeInfo implements the gocql.TypeInfo interface
   type JSONBTypeInfo struct {
        proto byte
   }
   
   // Type implements the gocql.TypeInfo interface
   func (j JSONBTypeInfo) Type() gocql.Type {
        return typeJSONB
   }
   
   // Version implements the gocql.TypeInfo interface
   func (j JSONBTypeInfo) Version() byte {
        return j.proto
   }
   
   // Custom implements the gocql.TypeInfo interface
   func (j JSONBTypeInfo) Custom() string {
        return ""
   }
   
   // New implements the gocql.TypeInfo interface
   func (j JSONBTypeInfo) New() interface{} {
        return new([]byte)
   }
   
   // NewWithError implements the gocql.TypeInfo interface
   func (j JSONBTypeInfo) NewWithError() (interface{}, error) {
        return new([]byte), nil
   }
   
   // JSONBCQLType implements the gocql.CQLType interface
   type JSONBCQLType struct {
   }
   
   // TypeInfo implements the gocql.CQLType interface
   func (j JSONBCQLType) TypeInfo(proto int) gocql.TypeInfo {
        return JSONBTypeInfo{proto: byte(proto)}
   }
   
   // Marshal implements the gocql.CQLType interface
   func (j JSONBCQLType) Marshal(info gocql.TypeInfo, value interface{}) 
([]byte, error) {
        return gocql.Marshal(gocql.NewNativeType(info.Version(), 
gocql.TypeBlob, ""), value)
   }
   
   // Unmarshal implements the gocql.CQLType interface
   func (j JSONBCQLType) Unmarshal(info gocql.TypeInfo, value []byte, dest 
interface{}) error {
        return gocql.Unmarshal(gocql.NewNativeType(info.Version(), 
gocql.TypeBlob, ""), value, dest)
   }
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to