@staticmethod
def _sort_query(query, sort=None):
    """
        Adds sorting clauses to the query.

        :param query: base SQL query
        :param sort: optional dictionary where keys are column names to sort by, and values are
         the order (asc/desc)
        :return: SQLAlchemy AppenderQuery object
        """
    if sort:
        for column, order in sort.items():
            if order == 'desc':
                column = column.desc()
            query = query.order_by(column)
    return query
