sqlalchemy 判断字段是否存在

1、low方法:

  

(1)person_obj=session.query(Person).filter(Person.name=='jack')
print (person_obj.count())


(2)person_obj=session.query(Person).filter(Person.name=='jack').fist()
View Code

2、高级用法:

  

from sqlalchemy.sql import exists

1.ret = self.session.query(exists().where(db_models.User.name == 'jack')).scalar()

2.self.session.query(db_models.User).filter_by(name='John Smith').exists()
       ).scalar()
View Code
原文地址:https://www.cnblogs.com/zjchao/p/9361846.html