dtoubelis / sails-cassandra

Cassanda database adapter for Sails.js
MIT License
26 stars 11 forks source link

Model query sort by timeuuid field #30

Closed victorbadila closed 9 years ago

victorbadila commented 9 years ago

I have a model with the following attribute:

id: { 
  type: 'string', 
  autoIncrement: true,
  primaryKey: true
}

The string id translates into timeuuid on cassandra side. However when trying to query the table sorting by id:

Entity2
  .find()
  .sort({id: 'desc'})
  .exec(function cb(err, ents) { ... });

the entities do not arrive in the normal order, and this can be seen by checking the createdAt column, which I have not disabled from the model.

I know that in cql in order to make comparisons between timeuuid fields one could use 'dateof' function, which extracts the timestamp from a timeuuid. Any idea if I am doing something wrong in my query or if the functionality I am trying to achieve is / will be supported in sails-cassandra?

dtoubelis commented 9 years ago

sort() is not supported by sails-cassandra as indicated here and it is likely will never be supported. Cassandra is NOT RELATIONAL DATABASE and records can only be sorted in CLUSTERING ORDER which is defined by underlying data model (also see here). So having sorts like in relational database is not possible.