gocqlx Updatebuilder and get wrong result

275 Views Asked by At

first, my table design are follow:

create table io
(
    qa         text primary key,
    created_at text,
    messages   list<frozen<message>>,
    reply      boolean,
    resolve    boolean,
    updated_at text,
    user       text,
    uuid       uuid
)

and my message of UDT

create type message
(
    time    text,
    who     tinyint,
    content text,
    images  map<text, blob>
);

my struct in golang are follow:

type Questions []Question

type Question struct {
    Uuid      gocql.UUID `json:"uuid"`
    User      string     `json:"user"`
    Reply     bool       `json:"reply"`
    Qa        string     `json:"qa"`
    CreatedAt string     `json:"created_at"`
    UpdatedAt string     `json:"updated_at"`
    Resolve   bool       `json:"resolve"`
    Messages  Messages   `json:"messages"`
}

type Messages []Message

type Message struct {
    Time    string            `json:"time"`
    Who     int               `json:"who"`
    Content string            `json:"content"`
    Images  map[string]string `json:"images"`
}

I use package of gocqlx to build my query,and insert data seems look like correct

...strat the session
...set meta table
...append message to messages (slice of message)
...finally, I run the this
if err := s.Query(t.UpdateBuilder().Add("messages").Set("updated_at").ToCql()).BindStruct(q).ExecRelease(); err != nil {
        log.Println("Send message error: ", err)
    }

print this query session.Query(table.UpdateBuilder().Add("messages").Set("updated_at").ToCql()).BindStruct(question)

[query statement="UPDATE io SET messages=messages+?,updated_at=? WHERE qa=? " values=[[{Time:2020-05-23 22:15:10+0800 Who:0 Content:yah yah yah Images:map[]}] 2020-05-23 22:15:10+0800 20200523221510] 

that will be right on executed. but when I check data in cassandra. I look null list value

| qa            | created_at             | messages   
------------------------------------------------------------------------------------------              
|20200523221510 |2020-05-23 22:15:10+0800| [{time:NULL,who:NULL,content:NULL,images:{}}] 

where's wrong ?

1

There are 1 best solutions below

0
KadoBOT On

Your struct needs to have a cql tag. Something like:

type Questions []Question

type Question struct {
    Uuid      gocql.UUID `json:"uuid" cql:"uuid"`
    // ...
}