def get_events(criteria)
      return {} if criteria.empty?

      query = events

      criteria.each_with_index do |item, i|
        filter_method = filter_method_name(i)
        if item[:since_version]
          query = query.send(filter_method, Sequel.lit('_entity_id = ? AND entity_version > ?', item[:id], item[:since_version]))
        else
          query = query.send(filter_method, Sequel.lit('_entity_id = ?', item[:id]))
        end
      end

      result = query.to_hash_groups(:_entity_id)

      result.each do |id, events|
        events.sort_by! { |attrs| [attrs[:entity_version], attrs[:id].to_s] }

        # Convert the attributes into event objects
        events.map! do |attrs|
          begin
            if self.class.native_json_hash
              hash = attrs[:data].to_h
            else
              hash = PigeonHole.parse(attrs[:data])
            end

            hash[:_id] = attrs[:id]
            hash[:entity_version] = attrs[:entity_version]
            hash[:entity_id] = attrs[:_entity_id]
            hash[:at] = attrs[:at]
            EntityStore::Config.load_type(attrs[:_type]).new(hash)
          rescue => e
            log_error "Error loading type #{attrs[:_type]}", e
            nil
          end
        end

        events.compact!
      end

      criteria.each do |item|
        result[item[:id].to_s] ||= []
      end

      result
    end
def get_events(criteria)
      return {} if criteria.empty?

      query = events

      criteria.each_with_index do |item, i|
        filter_method = filter_method_name(i)
        if item[:since_version]
          query = query.send(filter_method, Sequel.lit('_entity_id = ? AND entity_version > ?', item[:id], item[:since_version]))
        else
          query = query.send(filter_method, Sequel.lit('_entity_id = ?', item[:id]))
        end
      end

      result = query.to_hash_groups(:_entity_id)

      result.each do |id, events|
        events.sort_by! { |attrs| [attrs[:entity_version], attrs[:id].to_s] }

        # Convert the attributes into event objects
        events.map! do |attrs|
          begin
            if self.class.native_json_hash
              hash = attrs[:data].to_h
            else
              hash = PigeonHole.parse(attrs[:data])
            end

            hash[:_id] = attrs[:id]
            hash[:entity_version] = attrs[:entity_version]
            hash[:entity_id] = attrs[:_entity_id]
            hash[:at] = attrs[:at]
            EntityStore::Config.load_type(attrs[:_type]).new(hash)
          rescue => e
            log_error "Error loading type #{attrs[:_type]}", e
            nil
          end
        end

        events.compact!
      end

      criteria.each do |item|
        result[item[:id].to_s] ||= []
      end

      result
    end
Public:  get events for an array of criteria objects
           because each entity could have a different reference
           version this allows optional criteria to be specifed


 criteria  - Hash :id mandatory, :since_version optional

 Examples

 get_events_for_criteria([ { id: "23232323"}, { id: "2398429834", since_version: 4 } ] )

 Returns Hash with id as key and Array of Event instances as value