Class: Dynamodb::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamodb/relation.rb

Constant Summary collapse

OPERATOR_MAP =
{
  eq:           "=",
  gt:           ">",
  gte:          ">=",
  lt:           "<",
  lte:          "<=",
  begins_with:  "begins_with",
  between:      "BETWEEN"
}.freeze
QUERY_METHODS =
[
  :index_name, :consistent_read, :scan_index_forward,
  :key_condition_expression, :filter_expression, :expression_attribute_names,
  :expression_attribute_values, :projection_expression, :exclusive_start_key
].freeze
QUERY_INSTANCE_VARS =
[
  :limit
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Relation

Returns a new instance of Relation.



35
36
37
38
39
40
# File 'lib/dynamodb/relation.rb', line 35

def initialize(source)
  @source = source
  @attribute_expressors = {}
  @consistent_read = false
  @scan_index_forward = true
end

Instance Attribute Details

#attribute_expressorsObject (readonly)

Returns the value of attribute attribute_expressors.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def attribute_expressors
  @attribute_expressors
end

#consistent_readObject

Returns the value of attribute consistent_read.



9
10
11
# File 'lib/dynamodb/relation.rb', line 9

def consistent_read
  @consistent_read
end

#expression_attribute_namesObject (readonly)

Returns the value of attribute expression_attribute_names.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def expression_attribute_names
  @expression_attribute_names
end

#expression_attribute_valuesObject (readonly)

Returns the value of attribute expression_attribute_values.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def expression_attribute_values
  @expression_attribute_values
end

#filter_expressionObject (readonly)

Returns the value of attribute filter_expression.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def filter_expression
  @filter_expression
end

#index_nameObject

Returns the value of attribute index_name.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def index_name
  @index_name
end

#key_condition_expressionObject (readonly)

Returns the value of attribute key_condition_expression.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def key_condition_expression
  @key_condition_expression
end

#offset_keyObject

Returns the value of attribute offset_key.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def offset_key
  @offset_key
end

#projection_expressionObject (readonly)

Returns the value of attribute projection_expression.



10
11
12
# File 'lib/dynamodb/relation.rb', line 10

def projection_expression
  @projection_expression
end

#scan_index_forwardObject

Returns the value of attribute scan_index_forward.



9
10
11
# File 'lib/dynamodb/relation.rb', line 9

def scan_index_forward
  @scan_index_forward
end

#sourceObject

Returns the value of attribute source.



9
10
11
# File 'lib/dynamodb/relation.rb', line 9

def source
  @source
end

Instance Method Details

#allObject



63
64
65
# File 'lib/dynamodb/relation.rb', line 63

def all
  source._query(build_query)
end

#exclusive_start_keyObject



89
90
91
# File 'lib/dynamodb/relation.rb', line 89

def exclusive_start_key
  @offset_key
end

#limit(int) ⇒ Object



51
52
53
54
55
# File 'lib/dynamodb/relation.rb', line 51

def limit(int)
  @_limit = int
  build_expressions
  self
end

#query(args = {}) ⇒ Object



71
72
73
# File 'lib/dynamodb/relation.rb', line 71

def query(args = {})
  source._query(args)
end

#select(*args) ⇒ Object



57
58
59
60
61
# File 'lib/dynamodb/relation.rb', line 57

def select(*args)
  @projection_expression = args.flatten
  build_expressions
  self
end

#to_queryObject



67
68
69
# File 'lib/dynamodb/relation.rb', line 67

def to_query
  build_query
end

#where(args) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/dynamodb/relation.rb', line 42

def where(args)
  args.each do |k, v|
    setter = "#{k}=".to_sym
    self.has_method?(setter) ? self.send(setter, v) : add_attribute_query(k,v)
  end
  build_expressions
  self
end