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

selecting columns or aggregations and using raw option always gives cberror #212

Closed csaket closed 4 years ago

csaket commented 4 years ago

I am using 2.3.2 in my project and need to select particular columns only using the select option. If I do not use { raw: true } then the query works, but with the raw option, I get cberror "No valid callback function was provided"

    at f (.../node_modules/express-cassandra/lib/orm/apollo_error.js:177:15)
    at Function.f [as find] (.../node_modules/express-cassandra/lib/orm/base_model.js:750:11)
    at Function.tryCatcher (.../node_modules/bluebird/js/release/util.js:16:23)
    at Function.ret [as findAsync] (eval at makeNodePromisifiedEval (.../node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:16:23)

Can the two not go together?

Cassandra 3.11.2 CQL spec 3.4.4

I am using the async find

    let results = models.instance.Subscription.findAsync(limitQuery, { select: ['count(id)'] }, { raw: true });
masumsoft commented 4 years ago

Quoting from the documentation here:

Note that if you use the select option, then the results will always be raw plain objects instead of model instances.

Also the {raw: true} argument is in the wrong place (the reason for the error), it should be part of the options object where you put the select option like the following:

let results = models.instance.Subscription.findAsync(limitQuery, { select: ['count(id)'], raw: true });

Though it won't matter if you use raw:true or not here, because selecting columns will always produce a raw output.