masumsoft / express-cassandra

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.
http://express-cassandra.readthedocs.io
GNU Lesser General Public License v3.0
227 stars 67 forks source link

per partition limit operator is missing #196

Closed sobinsunny closed 3 years ago

sobinsunny commented 5 years ago

I'd be more flexibile if we can add PER PARTITION LIMIT operator in query

josiahjohnston commented 3 years ago

I think this amounts to a minor edit to src/utils/parser.js

New version:

parser.get_limit_clause = function f(queryObject) {
  let limit_clause = '';
  Object.keys(queryObject).forEach((k) => {
    const queryItem = queryObject[k];
    if (k.toLowerCase() === '$limit' || k.toLowerCase() === '$per_partition_limit') {
      if (typeof queryItem !== 'number') throw (buildError('model.find.limittype'));
      limit_clause = util.format('LIMIT %s', queryItem)
    }
    if (k.toLowerCase() === '$per_partition_limit') {
      limit_clause = 'PER PARTITION ' + limit_clause;
    }
  });
  return limit_clause;
};

I'm aspiring to test and put in a PR, but I'm juggling many other things and want to share this in case I get too distracted and forget to follow through.

masumsoft commented 3 years ago

@josiahjohnston thanks for the code, I've used this code along with some added tests to create a new release. v2.5.0

josiahjohnston commented 3 years ago

Thanks for being so amazingly responsive!