What advantage is there to overriding the == operator in an ORM?

大城市里の小女人 提交于 2019-12-23 02:03:13

问题


Apparently, a lot of ORMs do something like this:

query.filter(username == "bob")

to generate SQL like

... WHERE username = 'bob'

Why override the == operator instead of something like:

query.filter(username.eq("bob"))

回答1:


This is a subjective question, but in general I would say that the syntax for the former is more intuitive, and since many (if not most) ORM's do this it's generally expected (making it more intuitive).




回答2:


The whole point of orm is brideing the "impedance mismatch" between object and relational world , So in theory you can be blissfully unaware of "=" in sql world and work with "==" of the object world.



来源:https://stackoverflow.com/questions/1185537/what-advantage-is-there-to-overriding-the-operator-in-an-orm

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