为什么SQLAlchemy中不可能将布尔类型列用作ClauseElement本身?
session.query(Table).filter(Table.name == 'huszar', Table.valid)
当然Table.valid == True会起作用,但对我来说看起来有点难看……
最佳答案 我想也许你在0.7上并且ORM在单个filter()调用中还没有支持多个标准,这是在0.8中添加的,如果是独立的话,0.7似乎还需要表绑定列.一切都在0.8:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = "a"
id = Column(Integer, primary_key=True)
data = Column(String(20))
boolean = Column(Boolean)
# works
e = create_engine("sqlite://", echo=True)
# works
#e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
# works
#e = create_engine("mysql://scott:tiger@localhost/t