code: def where_before_entry(query, ref):
      
      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)
      )
docs: Generate a where clause for prior entries
  
      ref -- The entry of reference