import json


def retrieve_ecli(ecli, db_session):
    """
    Retrieves the ecli from a database
    
    :param ecli: The ECLI identifier
    :param db_session: a sqlalchemy session object
    """
    res = db_session.execute('select * from cases where ecli=:ecli', 
                                {"ecli":ecli})
    field_names = res.keys()
    results = res.fetchall()
    if len(results)>0:
        result = {field_names[i]: results[0][i] for i in range(len(field_names))}
        result['articles'] = json.loads(result['articles'])
        return result
    else:
        return None