Getting first row from sqlalchemy

后端 未结 4 1721
半阙折子戏
半阙折子戏 2020-12-13 17:13

I have the following query:

profiles = session.query(profile.name).filter(and_(profile.email == email, profile.password == password_hash))

4条回答
  •  不知归路
    2020-12-13 17:27

    Assuming you have a model User, you can get the first result with:

    User.query.first()

    If the table is empty, it will return None.

提交回复
热议问题