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.



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

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



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

def expression_attribute_names
  field_node.expression_attribute_names
end

#expression_attribute_valuesObject



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

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

#to_expressionObject



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

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