Database Reference
In-Depth Information
Writing code
Time to start something tangible! In this section, we will create the schema, insert the data,
and make interesting queries to retrieve the data. In a real application, you will have a GUI
with button and links to be able to log in, post, comment, upvote and downvote, and navig-
ate. Here, we will stick to what happens in the backend when you perform those actions.
This will keep the discussion from any clutter introduced by other software components.
Also, this section contains Cassandra Query Language ( CQL ), a SQL-like query lan-
guage for Cassandra. So, you can just copy these statements and paste them into your CQL
shell ( $CASSANDRA_HOME/bin/cqlsh ) to see it working. If you want to build an ap-
plication using these statements, you should be able to just use these statements in your fa-
vorite language via the CQL driver library that you can find at http://www.datastax.com/
download#dl-datastax-drivers . You can also download a simple Java application that is
built using these statements from my GitHub account ( https://github.com/naishe/mastering-
cassandra-v2 ) .
Setting up
Setting up a project involves creating a keyspace and tables. This can be done via the CQL
shell or from your favorite programming language.
Here are the statements to create the schema:
cqlsh> CREATE KEYSPACE weblog WITH REPLICATION = {'class':
'SimpleStrategy', 'replication_factor': 1};
cqlsh> USE weblog;
cqlsh:weblog> CREATE TABLE blogs (id uuid PRIMARY KEY,
blog_name varchar, author varchar, email varchar, password
varchar);
cqlsh:weblog> CREATE TABLE posts (id timeuuid, blog_id uuid,
posted_on timestamp, title text, content text, tags
set<varchar>, PRIMARY KEY(blog_id, id));
cqlsh:weblog> CREATE TABLE categories (cat_name varchar,
blog_id uuid, post_id timeuuid, post_title text, PRIMARY
KEY(cat_name, blog_id, post_id));
Search WWH ::




Custom Search