yaodong
7/29/2016 - 5:35 AM

count_in_sqlalchemy.py

query = some_model.query.filter_by(a=b)
count_q = query.statement.with_only_columns([db.func.count()]).order_by(None)
count = query.session.execute(count_q).scalar()
return count