Skip to content

Instantly share code, notes, and snippets.

@LukeTillman
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukeTillman/a2144e654fc05183afd2 to your computer and use it in GitHub Desktop.
Save LukeTillman/a2144e654fc05183afd2 to your computer and use it in GitHub Desktop.
Getting Started with Apache Cassandra and C#
using System;
using System.Linq;
using Cassandra;
namespace GettingStarted
{
class Program
{
static void Main(string[] args)
{
// Connect to the demo keyspace on our cluster running at 127.0.0.1
Cluster cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
ISession session = cluster.Connect("demo");
// Insert Bob
session.Execute("insert into users (lastname, age, city, email, firstname) values ('Jones', 35, 'Austin', 'bob@example.com', 'Bob')");
// Read Bob's information back and print to the console
Row result = session.Execute("select * from users where lastname='Jones'").First();
Console.WriteLine("{0} {1}", result["firstname"], result["age"]);
// Update Bob's age and then read it back and print to the console
session.Execute("update users set age = 36 where lastname = 'Jones'");
result = session.Execute("select * from users where lastname='Jones'").First();
Console.WriteLine("{0} {1}", result["firstname"], result["age"]);
// Delete Bob, then try to read all users and print them to the console
session.Execute("delete from users where lastname = 'Jones'");
RowSet rows = session.Execute("select * from users");
foreach(Row row in rows)
Console.WriteLine("{0} {1}", row["firstname"], row["age"]);
// Wait for enter key before exiting
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment