Class: Dynomite::Item::Query::Params::Base

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Helpers, Types
Defined in:
lib/dynomite/item/query/params/base.rb

Direct Known Subclasses

ExpressionAttribute, Filter, KeyCondition

Constant Summary

Constants included from Types

Types::TYPE_MAP

Instance Method Summary collapse

Methods included from Helpers

#all_where_field_names, #all_where_fields, #disable_index_for_any_or?, #disable_index_for_consistent_read?, #disable_index_for_not?, #normalize_expression_path, #normalize_project_expression, #query, #scan_required?, #with_where_groups

Methods included from Types

#type_map

Instance Method Details

#expression_string(expression) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/dynomite/item/query/params/base.rb', line 32

def expression_string(expression)
  if expression.is_a?(String)
    # Function filter expression is simple String
    expression
  else
    # Else expression is CompressionExpression object with extra info like .or?
    expression.build  # build the string
  end
end

#function_namesObject

To add function example:

  1. params/base.rb function_names

  2. query/chain.rb: add method

  3. params/function/begins_with.rb: filter_expression, attribute_names, attribute_values



11
12
13
# File 'lib/dynomite/item/query/params/base.rb', line 11

def function_names
  %w[attribute_exists attribute_type begins_with contains size_fn]
end

#join_expressionsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dynomite/item/query/params/base.rb', line 15

def join_expressions
  joined = ''
  @expressions.each do |expression|
    string = expression_string(expression)
    if joined.empty? # first pass
      joined << string
    else
      if !expression.is_a?(String) && expression.or?
        joined << " OR #{string}"
      else
        joined << " AND #{string}"
      end
    end
  end
  joined
end