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.



8
9
10
11
12
13
14
# File 'lib/aws-record/record/item_collection.rb', line 8

def initialize(search_method, search_params, model, client)
  @search_method = search_method
  @search_params = search_params
  @model_filter = @search_params.delete(:model_filter)
  @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.



28
29
30
31
32
33
34
35
36
# File 'lib/aws-record/record/item_collection.rb', line 28

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(&block)
  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.



72
73
74
75
76
77
# File 'lib/aws-record/record/item_collection.rb', line 72

def empty?
  items.each_page do |page|
    return false unless 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.



60
61
62
# File 'lib/aws-record/record/item_collection.rb', line 60

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 responses from the query or scan call.



46
47
48
49
50
# File 'lib/aws-record/record/item_collection.rb', line 46

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