使用 UDT:
注意:cqlsh:show version
[cqlsh 5.0.1 | Cassandra 2.2.1 | CQL spec 3.3.0 | Native protocol v4]
表
CREATE TYPE fullname (
firstname text,
lastname text
);
CREATE TABLE sample (
id int PRIMARY KEY,
name frozen <fullname>
);
代码:
type Frozen struct {
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
myobj := &Frozen{
Firstname: "pony",
Lastname: "jim",
}
if err := session.Query(`INSERT INTO sample (id, name) VALUES (?,?)`,
2, myobj).Exec(); err != nil {
fmt.Println(err)
}
我得到:
UDT are not available on protocols less than 3, please update config
更新配置?