SQLAlchemy get every row the matches query and loop through them

后端 未结 2 478
说谎
说谎 2021-01-23 18:47

I\'m new to Python and SQLAlchemy. I\'ve been playing about with retrieving things from the database, and it\'s worked every time, but im a little unsure what to do when the sel

2条回答
  •  广开言路
    2021-01-23 19:17

    the Usual way to work with orm queries is through the Session class, somewhere you should have a

    engine = sqlalchemy.create_engine("sqlite:///...")
    Session = sqlalchemy.orm.sessionmaker(bind=engine)
    

    I'm not familiar with flask, but it likely does some of this work for you.

    With a Session factory, your application is instead

    session = Session()
    entries = session.query(Application) \
              .filter_by(...) \
              .all()
    

提交回复
热议问题