Reputation: 1527
How can i insert something like this in cassandra:
{
"custID" : '12736467',
"date" : '2013-06-10',
"orderID" : 19482065,
"amount" : 216.28,
"items" : [
{ "id" : 1
"sku" : 87482734,
"quantity" : 4
},
{ "id":2
"sku" : 32851042,
"quantity" : 2
}
]
}
I thought the best way to store this data in cassandra is to create one table with family column:
custId | date | orderID | amount | items
id | sku | quantity
12736467 2013-06-10 19482065 216.28 1 87482734 4
2 32851042 2
create table items {
id text,
sku int,
quantity int};
create table test {
custId text,
date bigint,
orderId text,
amount float,
items list<items >,
PRIMARY KEY ((custId))
};
but how can I do insert into this table without using update for each time (insert into test ...).
Upvotes: 1
Views: 5092
Reputation: 6667
Instead of creating a table, it is better to create a User Defined Type.
Then use the following:
INSERT INTO items ("custId", date, "orderId", amount, items)
VALUES ( 'custid', 123456, 'orderid', 10.0,
[ { 'id' : '1', 'sku' : 12345, 'quantity' : 4 },
{ 'id' : '2', 'sku' : 12345, 'quantity' : 2 }]);
Upvotes: 1