Reputation: 1468
I have a column in cassandra which is of type set. Usig gocql I want to accept that column in golang code.So while accepting what should be the datatype of the variable in which the entire set is accepted.
e.g:
err = session.Query("select product_list from category where category_id=?",key).Scan(&productIdList)
Product_list is of type set.So what should be the data type of productIdList in golang?
Upvotes: 1
Views: 2146
Reputation: 25245
It looks like gocql uses a slice or array by default for Cassandra's set type.
If that's not what you want it does let you define one of your own using the gocql.Marshaller and gocql.Unmarshaller interfaces.
So for example:
type Set map[string]bool
func (s Set) UnmarshalCQL(info TypeInfo, data []byte) error {
/* code to unmarshal your set into a Go map. from cql results */
}
func (s Set) MarshalCQL(info TypeInfo) ([]byte, error) {
/* code to marshal your set out of a go map for cql to use */
}
This does however mean that you'll have to write the set output parsing yourself.
Upvotes: 2