Still trying to understand Cassandra I want users to see list of messages under a date they received from other users in this format below
CREATE TABLE user_messages (
userid bigint,
messages LIST<FROZEN<message>>,
creation_date text,
PRIMARY KEY (userid, creation_date)
);
.............8/3/2018...................
name: victor
content: ********
name: kelly
content: ******
.............7/3/2018...................
name: Vicky
content: *******
.............6/3/2018...................
name: Vicky
content: *******
If this design is correct how can i handle the insert operation?
Everytime a user wants to send message to a user do i need to check first if the
userid and date exist if no insert, if yes i update the table to add the message
inside the message list column.
Every time a user send a message to a user, use update statement like below
UPDATE user_messages
SET messages = messages + [{sender:2, message:'A'}]
WHERE userid = 1 AND creation_date = '2018-03-08';
UPDATE user_messages
SET messages = messages + [{sender:3, message:'B'}]
WHERE userid = 1 AND creation_date = '2018-03-08';
SELECT * FROM user_messages WHERE userid = 1 AND creation_date = '2018-03-08';
Output :
userid | creation_date | messages
--------+---------------+--------------------------------------------------------
1 | 2018-03-08 | [{sender: 2, message: 'A'}, {sender: 3, message: 'B'}]