目录

简介

Flask-SQLAlchemy is an extension for Flask that adds support for SQLAlchemy to your application. It requires SQLAlchemy 0.8 or higher. It aims to simplify using SQLAlchemy with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.

常用语句

求和

result = Poem.query.with_entities(func.sum(Poem.view_num).label('sum_result')).filter(Poem.author_id == self.id).first()
return result.sum_result

联表查询

tags = Tag.query.with_entities(Tag.id, Tag.name, func.count().label('poem_cnt'))\
            .outerjoin(poem_tag).group_by(Tag.id).order_by("poem_cnt desc")

删除记录

db.session.delete(tag)

参考