Class: Rom::Dynamo::GlobalIndexDataset

Inherits:
Dataset
  • Object
show all
Defined in:
lib/rom/dynamo/relation.rb

Overview

Dataset queried via a Global Index

Instance Attribute Summary collapse

Attributes inherited from Dataset

#connection, #name

Instance Method Summary collapse

Methods inherited from Dataset

#delete, #index_restrict, #initialize, #insert, #restrict

Constructor Details

This class inherits a constructor from Rom::Dynamo::Dataset

Instance Attribute Details

#indexObject

Returns the value of attribute index.



117
118
119
# File 'lib/rom/dynamo/relation.rb', line 117

def index
  @index
end

Instance Method Details

#each(&block) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rom/dynamo/relation.rb', line 119

def each(&block)
  # Pull record IDs from Global Index
  keys = []; each_item({
    key_conditions: @conditions,
    index_name: @index
  }) { |hash| keys << hash_to_key(hash) }

  # Bail if we have nothing
  return if keys.empty?

  # Query for the actual records
  ddb.batch_get_item({
    request_items: { name => { keys: keys } },
  }).each_page do |page|
    out = page[:responses][name]
    out.each(&block)
  end
end