def execute_query(filename: str) -> Optional[pd.DataFrame]:
    "Run SQL from a file. It will return a Pandas DataFrame if it selected\n    anything; otherwise it will return None.\n\n    I do not recommend you use this function too often. In general we should be\n    using the SQLAlchemy ORM. That said, it's a nice convenience, and there are\n    times where this function is genuinely something you want to run.\n    "
    with open(os.path.join(QUERIES_DIR, secure_filename(filename))) as f:
        query = f.read()
    with db.engine.connect() as conn:
        res = conn.execute(query)
        try:
            df = pd.DataFrame(res.fetchall(), columns=res.keys())
            return df
        except ResourceClosedError:
            return None
Run SQL from a file. It will return a Pandas DataFrame if it selected
anything; otherwise it will return None.

I do not recommend you use this function too often. In general we should be
using the SQLAlchemy ORM. That said, it's a nice convenience, and there are
times where this function is genuinely something you want to run.
def execute_query(filename: str) -> Optional[pd.DataFrame]:
    "Run SQL from a file. It will return a Pandas DataFrame if it selected\n    anything; otherwise it will return None.\n\n    I do not recommend you use this function too often. In general we should be\n    using the SQLAlchemy ORM. That said, it's a nice convenience, and there are\n    times where this function is genuinely something you want to run.\n    "
    with open(os.path.join(QUERIES_DIR, secure_filename(filename))) as f:
        query = f.read()
    with db.engine.connect() as conn:
        res = conn.execute(query)
        try:
            df = pd.DataFrame(res.fetchall(), columns=res.keys())
            return df
        except ResourceClosedError:
            return None