def dictfetchall(connection, sql, *params, **kwargs):
    """
    Return all rows from a cursor as a dict,
    if kwargs.get("format") == 'list', return as list
    """

    with connection.cursor() as cursor:
        cursor.execute(sql, params)

    columns = [col[0] for col in cursor.description]

    if kwargs.get("format") == "list":
        return list(cursor.fetchall())

    return [dict(zip(columns, row)) for row in cursor.fetchall()]