Skip to content

Latest commit

 

History

History
94 lines (73 loc) · 2.42 KB

quickstart.md

File metadata and controls

94 lines (73 loc) · 2.42 KB

Quick Start with Accord Transactions

This guide will get you up and running with Accord transactions in minutes. We'll cover setup, basic usage, and your first transaction.

Prerequisites

  • Docker installed (for single-node testing)
  • OR Homebrew (for multi-node setup)
  • Basic familiarity with CQL

Setup Options

Option 1: Docker (Single Node)

# Pull and run the container
docker pull pmcfadin/cassandra-accord
docker run -d --name cassandra-accord -p 9042:9042 pmcfadin/cassandra-accord

# Connect with cqlsh
docker exec -it cassandra-accord ./bin/cqlsh

Option 2: Multi-Node Lab (via easy-cass-lab)

# Install easy-cass-lab
brew tap rustyrazorblade/rustyrazorblade
brew install easy-cass-lab

# Create a new cluster
mkdir my-cluster && cd my-cluster
easy-cass-lab init -c 3 -s 1 mycluster
easy-cass-lab up

Your First Transaction

Let's create a simple inventory management system:

-- Create a table with transactions enabled
CREATE TABLE demo.products (
    item text,
    inventory_count decimal,
    PRIMARY KEY (item)
) WITH transactional_mode = 'full';

-- Insert initial inventory
INSERT INTO demo.products(item, inventory_count) 
VALUES ('PlayStation 5', 100);

-- Run a transaction to update inventory
BEGIN TRANSACTION
    UPDATE demo.products 
    SET inventory_count -= 1 
    WHERE item='PlayStation 5';
COMMIT TRANSACTION;

-- Verify the result
SELECT * FROM demo.products WHERE item='PlayStation 5';

Example Transactions

  1. Bank Transfer
BEGIN TRANSACTION
    UPDATE accounts SET balance -= 100 WHERE user_id = 'alice';
    UPDATE accounts SET balance += 100 WHERE user_id = 'bob';
COMMIT TRANSACTION;
  1. User Registration
BEGIN TRANSACTION
    LET existing = (SELECT email FROM users WHERE email = '[email protected]');
    
    IF existing IS NULL THEN
        INSERT INTO users(id, email) VALUES (uuid(), '[email protected]');
    END IF
COMMIT TRANSACTION;

Next Steps

Getting Help