Boolean value return from Neo4j cypher query without CASE

孤街醉人 提交于 2019-12-13 02:59:26

问题


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


回答1:


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}'.



来源:https://stackoverflow.com/questions/36930174/boolean-value-return-from-neo4j-cypher-query-without-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!