简体   繁体   中英

How can I do this query in Flask-SQLAlchemy?

is it possible and how this querie in a flask with SQLALchemy

SELECT * FROM records
WHERE status = 'SCHEDULE'
OR status = 'RECORDING'
OR status = 'FAILED'
AND fail_type='S3_CONNECTION'

I am using the following code:

Record().query.filter(
    Record.id == record_id,
    Record.status in (Status.SCHEDULED, Status.RECORDING)
    Record.status == Status.FAILED
    Record.fail_type == 'S3_CONNETION'
).one()

But this is all AND instead or or and

How can I do that querie?

Thanks

Try this query:

from sqlalchemy import or_
Record().query.filter(
    Record.id == record_id,
    or_(Record.status in (Status.SCHEDULED, Status.RECORDING,)
    Record.status == Status.FAILED),
    Record.fail_type == 'S3_CONNETION'
).one()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM