Database Reference
In-Depth Information
Retrieving data
Now that we have data inserted for our application, we need to retrieve it. To blog applica-
tions, usually the blog name serves as the primary key in their database. So, when you re-
quest cold-caffein.blogspot.com , a blog metadata table with the blog ID as cold-caf-
fein exists. We, on the other hand, can use the blog uuid to request to serve the con-
tents. So, we assume that having the blog ID is handy.
Let's display posts. We should not load all the posts for the user upfront. It is not a good
idea from the usability point of view. It demands more bandwidth, and it is probably a lot
of reads for Cassandra. So first, let's pull two posts at a time from ones posted earlier:
cqlsh:weblog> select * from posts where blog_id =
83cec740-22b1-11e4-a4f0-7f1a8b30f852 order by id desc limit
2;
blog_id | id | content |
posted_on | tags | title
-----------+-------------+-----------------+--------------------------+-----------------------+--------------
83cec… | c2240… | posterior=(prior*likelihood)/evidence |
2014-08-12 11:29:49+0530 | {'maths', 'random'} | Fooled
by randomness...
83cec… | 965a2… | hey howdy! |
2014-08-12 11:25:21+0530 | {'random', 'welcome'}
| first post
(2 rows)
This was the first page. For the next page, we can use an anchor. We can use the last post's
ID as an anchor, as its timeuuid increases monotonically with time. So, posts older than
that will have the post ID with smaller values, and this will work as our anchor:
cqlsh:weblog> select * from posts where blog_id =
83cec740-22b1-11e4-a4f0-7f1a8b30f852 and id <
8eab0c10-2314-11e4-bac7-3f5f68a133d8 order by id desc limit
2;
Search WWH ::




Custom Search