Brett
Brett

Reputation: 1781

Boolean value return from Neo4j cypher query without CASE

I know that you can do this

match (user:User {username:'${username}', password:'${password}'})
            RETURN
            CASE WHEN user.blocked='true' THEN true ELSE false END as blocked,
            user.username as username,
            user.uid as uid

But I hope to find a shorter way to return booleans with cypher, I am using nodejs and having CASE like this on every boolean props my objects have seems very verbose... Is there a better way ? thanks

Upvotes: 1

Views: 732

Answers (1)

cybersam
cybersam

Reputation: 67019

You can replace this:

CASE WHEN user.blocked='true' THEN true ELSE false END AS blocked

with this:

user.blocked='true' AS blocked

Now, if you actually stored a boolean value in the blocked property (instead of a string), the above can be simplified even further:

user.blocked AS blocked

Aside: To further improve performance, you should probably use parameters instead of '${username}' and '${password}'.

Upvotes: 3

Related Questions