Class: Aws::Record::ItemCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aws-record/record/item_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(search_method, search_params, model, client) ⇒ ItemCollection

Returns a new instance of ItemCollection



19
20
21
22
23
24
# File 'lib/aws-record/record/item_collection.rb', line 19

def initialize(search_method, search_params, model, client)
  @search_method = search_method
  @search_params = search_params
  @model = model
  @client = client
end

Instance Method Details

#each(&block) ⇒ Enumerable<Aws::Record>

Provides an enumeration of the results of a query or scan operation on your table, automatically converted into item classes.

WARNING: This will enumerate over your entire partition in the case of query, and over your entire table in the case of scan, save for key and filter expressions used. This means that enumerable operations that iterate over the full result set could make many network calls, or use a lot of memory to build response objects. Use with caution.

Returns:

  • (Enumerable<Aws::Record>)

    an enumeration over the results of your query or scan request. These results are automatically converted into items on your behalf.



38
39
40
41
42
43
44
45
46
47
# File 'lib/aws-record/record/item_collection.rb', line 38

def each(&block)
  return enum_for(:each) unless block_given?
  items.each_page do |page|
    @last_evaluated_key = page.last_evaluated_key
    items_array = _build_items_from_response(page.items, @model)
    items_array.each do |item|
      yield item
    end
  end
end

#empty?Boolean

Checks if the query/scan result is completely blank.

WARNING: This can and will query your entire partition, or scan your entire table, if no results are found. Especially if your table is large, use this with extreme caution.

Returns:

  • (Boolean)

    true if the query/scan result is empty, false otherwise.



83
84
85
86
87
88
# File 'lib/aws-record/record/item_collection.rb', line 83

def empty?
  items.each_page do |page|
    return false if !page.items.empty?
  end
  true
end

#last_evaluated_keyHash

Provides the pagination key most recently used by the underlying client. This can be useful in the case where you're exposing pagination to an outside caller, and want to be able to “resume” your scan in a new call without starting over.

Returns:

  • (Hash)

    a hash representing an attribute key/value pair, suitable for use as the exclusive_start_key in another query or scan operation. If there are no more pages in the result, will be nil.



71
72
73
# File 'lib/aws-record/record/item_collection.rb', line 71

def last_evaluated_key
  @last_evaluated_key
end

#pageArray<Aws::Record>

Provides the first “page” of responses from your query operation. This will only make a single client call, and will provide the items, if any exist, from that response. It will not attempt to follow up on pagination tokens, so this is not guaranteed to include all items that match your search.

Returns:

  • (Array<Aws::Record>)

    an array of the record items found in the first page of reponses from the query or scan call.



57
58
59
60
61
# File 'lib/aws-record/record/item_collection.rb', line 57

def page
  search_response = items
  @last_evaluated_key = search_response.last_evaluated_key
  _build_items_from_response(search_response.items, @model)
end