Class: DynamoidAdvancedWhere::Nodes::ExistsNode

Inherits:
BaseNode
  • Object
show all
Includes:
Concerns::Negatable, Concerns::SupportsLogicalAnd, Concerns::SupportsLogicalOr
Defined in:
lib/dynamoid_advanced_where/nodes/exists_node.rb

Instance Attribute Summary collapse

Attributes inherited from BaseNode

#expression_prefix

Instance Method Summary collapse

Methods included from Concerns::SupportsLogicalOr

#or

Methods included from Concerns::SupportsLogicalAnd

#and

Methods included from Concerns::Negatable

#negate

Constructor Details

#initialize(field_node:) ⇒ ExistsNode

Returns a new instance of ExistsNode.



13
14
15
16
17
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 13

def initialize(field_node:)
  self.field_node = field_node
  self.prefix = SecureRandom.hex
  freeze
end

Instance Attribute Details

#field_nodeObject

Returns the value of attribute field_node.



12
13
14
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 12

def field_node
  @field_node
end

#prefixObject

Returns the value of attribute prefix.



12
13
14
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 12

def prefix
  @prefix
end

Instance Method Details

#expression_attribute_namesObject



26
27
28
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 26

def expression_attribute_names
  field_node.expression_attribute_names
end

#expression_attribute_valuesObject



30
31
32
33
34
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 30

def expression_attribute_values
  {
    ":#{prefix}" => nil
  }
end

#to_expressionObject



19
20
21
22
23
24
# File 'lib/dynamoid_advanced_where/nodes/exists_node.rb', line 19

def to_expression
  "NOT(
    attribute_not_exists(#{field_node.to_expression})
    or #{field_node.to_expression} = :#{prefix}
  )"
end