I am using Cequel in Rails. I would like to query something like
Event.where("started_at >?", Time.now)
in ActiveRecord. But I don't know how to do that in cequel.
I am using Cequel in Rails. I would like to query something like
Event.where("started_at >?", Time.now)
in ActiveRecord. But I don't know how to do that in cequel.
In order to perform efficient range queries over a timestamp, you'll need to group your events under a parent object, and use the
started_at
as your clustering column (the last column in your primary key). So, for instance, if events belong to venues, you might set up something like this:This means you can efficiently perform queries over ranges of start times. A few things to note:
started_at
key is a TimeUUID to ensure uniqueness. TimeUUIDs encapsulate a timestamp, and can be queried over time rangesbelongs_to
declaration. It describes a parent/child relationship.So to create an event, you'd do something like:
Then to query for a range of events by start time:
Note that you can't do range queries by arbitrary columns—only by clustering columns in the primary key. So you can't have a table that allows queries over
start_time
andend_time
, for instance.