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

if_not_exist doesn't return a value #206

Closed borabaloglu closed 4 years ago

borabaloglu commented 4 years ago

Hi, I don't wanna use duplicated primary keys in my table. I tried to use "if_not_exist: true" option but I have to check a return value so I can throw an error like "this email is already in use".

I looked up the docs but couldn't find any options. Could you please help me about it?

Note: express-cassandra version is 2.3.0, node version is 12.10.0

JefferyHus commented 4 years ago

Wouldn't a normal SELECT email FROM table WHERE primary_key = %.

And using the ORM you can do this:

//If you specifically expect only a single object after find, you may do this
models.instance.Person.findOne({name: 'John'}, function(err, john){
    if(err) throw err;
    //The variable `john` is a model instance containing the person named `John`
    //`john` will be undefined if no person named `John` was found
    console.log('Found ', john.name);
});
masumsoft commented 4 years ago

closing due to inactivity.