def _dict_factory(cursor, row):
    """
    This is a helper function to create a dictionary using the column names
    from the database as the keys

    """
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0].lower()] = row[idx] # lower() to match postgres.extras.RealDictCursor
    return d