Chrome Extension

Using OR on filter query SQLAlchemy

You can apply OR in SQLAlchemy by importing _or from SQLAlchemy and then passing conditions on models.
from sqlalchemy import or_

session.query(
    UserModel.id,
    UserModel.first_name
).filter(
    or_(
        UserModel.username == 'john', 
        UserModel.username == 'michael'
    )
).all()
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the code snippet, we are applying OR condition on the username column where it will get the records if its username column has the value 'john' or 'michael'.

Was this helpful?
0 Comments