doumiyi7063 2014-03-11 01:13
浏览 68
已采纳

在Golang中接受Cassandra的Set数据类型

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?

  • 写回答

1条回答 默认 最新

  • douchengfei3985 2014-03-11 02:32
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码