Paginating over rows in a partition
As our users create more and more status updates, we'll build pagination functionality into MyStatus so that the information on the page doesn't overwhelm readers. For the sake of convenience, let's say that each page will only contain three status updates.
To retrieve the first page, we'll use the LIMIT
keyword that we first encountered in Chapter 2, The First Table:
SELECT "id", DATEOF("id"), "body" FROM "user_status_updates" WHERE "username" = 'alice' LIMIT 3;
As expected, Cassandra will give us the first three rows in ascending order of id
:
Now, we'll ask for the collection of rows where the id
value is strictly greater than the last id
we saw:
SELECT "id", DATEOF("id"), "body" FROM "user_status_updates" WHERE "username" = 'alice' AND id > 3f9df710-e8f7-11e3-9211-5f98e903bf02 LIMIT 3;
This is similar to the pagination query for users
that we made in Chapter 2, The First Table, but it's in some ways simpler. We keep the restriction of rows to alice
's...