本文介绍了不使用CASE的Neo4j密码查询返回的布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以做到

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

但是我希望找到一种更短的方法来返回带有密文的布尔值,我正在使用nodejs以及我的对象在每个布尔道具上都具有这种情况的CASE似乎非常冗长...是否有更好的方法?谢谢

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

推荐答案

您可以替换为:

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

现在,如果您实际上将布尔值存储在 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

此外:为了进一步提高性能,您可能应该使用,而不是 $ {username}和 $ {password}。

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

这篇关于不使用CASE的Neo4j密码查询返回的布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 19:59