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

find by uuid not working #176

Closed shatayuD closed 5 years ago

shatayuD commented 5 years ago

I'm using latest i.e. 2.2.3 version. I tried to query with partition key uuid. I'm just returning promise here to caller method

var models = require('express-cassandra');
return models.instance.Customer.findAsync({id:id})

But got exception as

  cause: { apollo.model.validator.invalidvalue: Invalid Value: "8cc86755-b435-4b40-89dd-ed9baa9de116" for Field: id (Type: uuid)
    at f (C:\projects\generator\myapp\node_modules\express-cassandra\lib\orm\apollo_error.js:174:15)
    at Object.f [as get_db_value_expression] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:97:11)
    at buildQueryRelations (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:324:24)
    at Object.f [as extract_query_relations] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:392:5)
    at C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:461:41
    at Array.forEach (<anonymous>)
    at Object.f [as _parse_query_object] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:401:28)
    at Object.f [as get_filter_clause] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:472:29)
    at Object.f [as get_where_clause] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\utils\parser.js:507:17)
    at Function.f [as get_find_query] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\orm\base_model.js:296:28)
    at Function.f [as find] (C:\projects\generator\myapp\node_modules\express-cassandra\lib\orm\base_model.js:761:26)
    at Function.tryCatcher (C:\projects\generator\myapp\node_modules\bluebird\js\release\util.js:16:23)
    at Function.ret [as findAsync] (eval at makeNodePromisifiedEval (C:\projects\generator\myapp\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:14:23)

I also referred to question on stackoverflow and also checked bug but not working for me But I dont want to index the other fields as of now CustomerModel.js is as follows :

module.exports = {
    fields: {
        id: { type: "uuid", default: { "$db_function": "uuid()" } },
        name: {
            type: "text",
            rule: {
                validators: [
                    {
                        validator: function (value) { return value < 10 },
                        message: function (value) { return 'maximum length allowed is 10, passed length is ' + value.length }
                    },
                    {
                        validator: function (value) { return value.length > 0 },
                        message: function (value) { return 'name is required' }
                    }
                ]

            }
        },
        address: "text",
        city: "text",
        created: "timestamp"
    },
    key: ["id"]
}

Kindly help me to sort this out. is it that id is queried with quotes to cassandra for uuid field ? Please guide me how to solve this issue. Also I'm not saving it like shown here, I have id from where I want to find the model.

shatayuD commented 5 years ago

Same thing is happening while updating the model.

masumsoft commented 5 years ago

Looks like you are passing the uuid as a string. You need to use the uuid datatype instead. If you want to convert a string uuid to uuid type, then you can use the models.uuidFromString(your_string_uuid). To get details about datatypes and javascript to cassandra type conversions, have a look at the docs:

https://express-cassandra.readthedocs.io/en/stable/datatypes/

shatayuD commented 5 years ago

thank you so much. I've used it and this is working fine now