Skip to content

Latest commit

 

History

History
69 lines (56 loc) · 2.03 KB

step5-cassandra.md

File metadata and controls

69 lines (56 loc) · 2.03 KB
Atomicity and Batches in Apache Cassandra® ℹ️ For technical support, please contact us via email or LinkedIn.
⬅️ Back Step 5 of 8 Next ➡️
Updating a shopping cart

Next, for your practice, use a single-partition batch to add another movie into the same shopping cart and update the running total.

✅ Update the shopping cart:

Solution
BEGIN BATCH
  INSERT INTO shopping_cart 
         (cart_id, title, year, price, user) 
  VALUES (b7255608-4a42-4829-9b84-a355e0e5100d, 
         'Edward Scissorhands', 1990, 3.99, 
         'joe@datastax.com');
  UPDATE shopping_cart SET total = 6.97
  WHERE cart_id = b7255608-4a42-4829-9b84-a355e0e5100d
  IF total = 2.98;
APPLY BATCH;  

✅ Retrieve the shopping cart:

Solution
SELECT total, price, title, year 
FROM shopping_cart
WHERE cart_id = b7255608-4a42-4829-9b84-a355e0e5100d;
⬅️ Back Next ➡️