from .. import db
from ..decorators import background
from ..models import QueryResult


@background
def delete_query_result(query_result_id, *args, **kwargs):
    with kwargs['app'].app_context():
        query_result = QueryResult.query.get(query_result_id)
        if query_result is None:
            raise Exception(f'QueryResult {query_result_id} not found')
        query_result.delete()
        db.session.commit()
