[go: up one dir, main page]

Skip to content

[Todo] Current Model.query scheme is considered legacy

In the current code, all database queries are done using the model query form like:

Samples.query.get_or_404(...)

This is considered outdated by Flask-SQLAlchemy and SQLAlchemy. Hence, we will have to change our queries to the new format in the long term using "db.session.execute()" and select. Atypical query will have the form:

user = db.session.execute(db.select(User).filter_by(username=username)).one()

users = db.session.execute(db.select(User).order_by(User.username)).scalars()

or using Flask-SQLAlchemy internal function

  • SQLAlchemy.get_or_404()
  • SQLAlchemy.first_or_404()
  • SQLAlchemy.one_or_404()

See: https://flask-sqlalchemy.palletsprojects.com/en/3.0.x/queries/ As well as: https://docs.sqlalchemy.org/en/14/orm/queryguide.html

It's related to issue #112 (closed) as the documentation of Flask-SQLAlchemy is the first stating this issue. This will become a problem, when sqlalchemy changes to 2.x.x ...

This will require some major changes to sample.py, documents.py, measurements.py and report.py. Maybe, we also have to update the SearchMIX class.