How does sqlachemy query method work?

前端 未结 1 962
自闭症患者
自闭症患者 2020-12-21 09:11

I am learning sqlachemy, I\'m relatively new to Python.

When I read its documentation, I saw this kind of usage, for example:

query.filter(Use

相关标签:
1条回答
  • 2020-12-21 09:46

    SQLAlchemy uses the various special method hooks to overload operator behaviour.

    For ==, the __eq__() method returns special objects that signify a SQL expression when compiled. To quote the documentation on the 'rich comparison' hooks:

    By convention, False and True are returned for a successful comparison. However, these methods can return any value, so if the comparison operator is used in a Boolean context (e.g., in the condition of an if statement), Python will call bool() on the value to determine if the result is true or false.

    See the ColumnOperators class in the SQLAlchemy source for the specific hooks implemented.

    0 讨论(0)
提交回复
热议问题