Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to new query API in SQLAlchemy 2.0 #970

Open
robintw opened this issue Aug 25, 2021 · 0 comments
Open

Switch to new query API in SQLAlchemy 2.0 #970

robintw opened this issue Aug 25, 2021 · 0 comments
Labels
rw_backlog_opt Optional items for RW rw_backlog Candidate tasks for Robin Task Package of work

Comments

@robintw
Copy link
Collaborator

robintw commented Aug 25, 2021

🐞 Overview

#830 is the issue for updating to support SQLAlchemy 1.4 and prepare for 2.0, and this involves making various changes as the SQLAlchemy API has had significant changes. One of these changes is a new recommended style for doing database queries. This is not required for v2.0, but it is recommended, and the old way will be deprecated and not shown in the docs etc.

The docs say:

The biggest visible change in SQLAlchemy 2.0 is the use of Session.execute() in conjunction with select() to run ORM queries, instead of using Session.query(). As mentioned elsewhere, there is no plan to actually remove the Session.query() API itself, as it is now implemented by using the new API internally it will remain as a legacy API, and both APIs can be used freely.

There are examples in the docs, but in our case code often looks like this:

session.query(User).all()

and it would need to be replaced with:

session.execute(
    select(User)
).scalars().all()

(I must admit that I don't like this style as much)

So, we should probably change this at some point, but it's not urgent as it isn't being removed from SQLAlchemy 2.0

@robintw robintw added the Task Package of work label Aug 25, 2021
@IanMayo IanMayo added the rw_backlog Candidate tasks for Robin label Sep 10, 2021
@IanMayo IanMayo added the rw_backlog_opt Optional items for RW label Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rw_backlog_opt Optional items for RW rw_backlog Candidate tasks for Robin Task Package of work
Projects
None yet
Development

No branches or pull requests

2 participants