使用gocql向Cassandra插入一个切片
我有一个表,其中有一个UDT的列表。当我尝试插入数据时,表中的所有字段都已正确填写,但列表中只包含空值。使用gocql向Cassandra插入一个切片,go,cassandra,gocql,Go,Cassandra,Gocql,我有一个表,其中有一个UDT的列表。当我尝试插入数据时,表中的所有字段都已正确填写,但列表中只包含空值。 类型和表格: create type dish ( name text, menu_id text, number int ); create table orders ( user text, id text, created_at timestamp, dishes list<frozen<dish>&
类型和表格:
create type dish (
name text,
menu_id text,
number int
);
create table orders (
user text,
id text,
created_at timestamp,
dishes list<frozen<dish>>,
status text,
primary key(id)
);
JSON:
插入:
if err := cassandraConn.Query("INSERT INTO orders(id, created_at, dishes, status, user) VALUES(?, ?, ?, ?, ?)",
order.Id, order.CreatedAt, order.Dishes, order.Status, order.User).Exec(); err != nil {
fmt.Println("Error while inserting order:")
return err
}
插入后的表如下所示:
123 | 2018-04-09 23:00:00.000000+0000 | [{name: null, menu_id: null, number: null}, {name: null, menu_id: null, number: null}] | pending | 1
你找到答案了吗?如果是,请分享。
if err := cassandraConn.Query("INSERT INTO orders(id, created_at, dishes, status, user) VALUES(?, ?, ?, ?, ?)",
order.Id, order.CreatedAt, order.Dishes, order.Status, order.User).Exec(); err != nil {
fmt.Println("Error while inserting order:")
return err
}
123 | 2018-04-09 23:00:00.000000+0000 | [{name: null, menu_id: null, number: null}, {name: null, menu_id: null, number: null}] | pending | 1