我如何在 Flask-SQLAlchemy 中执行此查询?
How can I do this query in Flask-SQLAlchemy?
是否可能以及如何使用 SQLALchemy 在烧瓶中进行查询
SELECT * FROM records
WHERE status = 'SCHEDULE'
OR status = 'RECORDING'
OR status = 'FAILED'
AND fail_type='S3_CONNECTION'
我正在使用以下代码:
Record().query.filter(
Record.id == record_id,
Record.status in (Status.SCHEDULED, Status.RECORDING)
Record.status == Status.FAILED
Record.fail_type == 'S3_CONNETION'
).one()
但这全是 AND 而不是 or or and
我该如何查询?
谢谢
试试这个查询:
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()
是否可能以及如何使用 SQLALchemy 在烧瓶中进行查询
SELECT * FROM records
WHERE status = 'SCHEDULE'
OR status = 'RECORDING'
OR status = 'FAILED'
AND fail_type='S3_CONNECTION'
我正在使用以下代码:
Record().query.filter(
Record.id == record_id,
Record.status in (Status.SCHEDULED, Status.RECORDING)
Record.status == Status.FAILED
Record.fail_type == 'S3_CONNETION'
).one()
但这全是 AND 而不是 or or and
我该如何查询?
谢谢
试试这个查询:
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()