def where_entry_first(query, ref):
    """ Generate a where clause where this is the first entry

    ref -- the entry of reference
    """
    return orm.select(
        e for e in query
        if e.local_date > ref.local_date or
        (e.local_date == ref.local_date and
         e.id >= ref.id
         )
    )