Class: Dynomite::Query
- Inherits:
-
Object
- Object
- Dynomite::Query
- Includes:
- Enumerable
- Defined in:
- lib/dynomite/query.rb
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #each(&block) ⇒ Object
- #index_name(name) ⇒ Object
-
#initialize(item, params) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
- #where(attributes) ⇒ Object
Constructor Details
#initialize(item, params) ⇒ Query
Returns a new instance of Query.
5 6 7 8 |
# File 'lib/dynomite/query.rb', line 5 def initialize(item, params) @item = item @params = params end |
Instance Method Details
#<<(item) ⇒ Object
10 11 12 |
# File 'lib/dynomite/query.rb', line 10 def <<(item) raise NotImplementedError end |
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/dynomite/query.rb', line 18 def each(&block) run_query.each(&block) end |
#index_name(name) ⇒ Object
22 23 24 |
# File 'lib/dynomite/query.rb', line 22 def index_name(name) self.class.new(@item, @params.merge(index_name: name)) end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/dynomite/query.rb', line 14 def inspect "#<Dynomite::Query [#{first(2).map(&:inspect).join(', ')}, ...]>" end |
#where(attributes) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dynomite/query.rb', line 26 def where(attributes) raise "attributes.size == 1 only supported for now" if attributes.size != 1 attr_name = attributes.keys.first attr_value = attributes[attr_name] name_key, value_key = "##{attr_name}_name", ":#{attr_name}_value" params = { expression_attribute_names: { name_key => attr_name }, expression_attribute_values: { value_key => attr_value }, key_condition_expression: "#{name_key} = #{value_key}", } self.class.new(@item, @params.merge(params)) end |