Module: Dynomite::Item::Query::Relation::Chain

Included in:
Dynomite::Item::Query::Relation
Defined in:
lib/dynomite/item/query/relation/chain.rb

Overview

Builds up the query with methods like where and eventually executes Query or Scan.

Instance Method Summary collapse

Instance Method Details

#attribute_exists(path) ⇒ Object



93
94
95
96
# File 'lib/dynomite/item/query/relation/chain.rb', line 93

def attribute_exists(path)
  @query[:attribute_exists] << path
  self
end

#attribute_not_exists(path) ⇒ Object



98
99
100
101
# File 'lib/dynomite/item/query/relation/chain.rb', line 98

def attribute_not_exists(path)
  @query[:attribute_not_exists] << path
  self
end

#attribute_type(path, type) ⇒ Object



103
104
105
106
# File 'lib/dynomite/item/query/relation/chain.rb', line 103

def attribute_type(path, type)
  @query[:attribute_type] << {path: path, type: type}
  self
end

#begins_with(path, substr) ⇒ Object

This is a function that accepts a path and a value. This is different from the comparision operator. IE: “”



110
111
112
113
# File 'lib/dynomite/item/query/relation/chain.rb', line 110

def begins_with(path, substr)
  @query[:begins_with] << {path: path, substr: substr}
  self
end

#consistent_read(value = true) ⇒ Object Also known as: consistent

Note consistent read it supported with GSI. You may want to use force_scan if really need a consistent read.



58
59
60
61
# File 'lib/dynomite/item/query/relation/chain.rb', line 58

def consistent_read(value=true)
  @query[:consistent_read] = value
  self
end

#contains(path, substr) ⇒ Object



115
116
117
118
# File 'lib/dynomite/item/query/relation/chain.rb', line 115

def contains(path, substr)
  @query[:contains] << {path: path, substr: substr}
  self
end

#excluding(*args) ⇒ Object



20
21
22
23
24
25
# File 'lib/dynomite/item/query/relation/chain.rb', line 20

def excluding(*args)
  ids = args.map do |object|
    object.is_a?(Dynomite::Item) ? object.id : object
  end
  self.not("id.in": ids)
end

#exclusive_start_key(hash) ⇒ Object Also known as: start_from, start_at, start



64
65
66
67
# File 'lib/dynomite/item/query/relation/chain.rb', line 64

def exclusive_start_key(hash)
  @query[:exclusive_start_key] = hash
  self
end

#force_scanObject

Disable use of index and query method. Force a scan method



51
52
53
54
# File 'lib/dynomite/item/query/relation/chain.rb', line 51

def force_scan
  @query[:force_scan] = true
  self
end

#index_name(name, suffix: 'index') ⇒ Object

Could add some magically behavior to strip off the -index if the index name is 3 characters long. but think that’s even more obscure.

suffix allows for shorter syntax:

index_name('created_at') vs index_name('created_at-index')

Note: Tried using the shorter index method name but it seems to conflict an index method. Even though Enumerable has an index method, it doesn’t seem to be the one thats conflicting. It’s somewhere else.



82
83
84
85
86
# File 'lib/dynomite/item/query/relation/chain.rb', line 82

def index_name(name, suffix: 'index')
  name = [name, suffix].compact.join('-') if !name.ends_with?('index') && suffix
  @query[:index_name] = name.to_s
  self
end

#limit(value) ⇒ Object

The default limit for both Scan and Query in Amazon DynamoDB is 1 MB of data read. It’ll stop per api call regardless of the limit you set once it hits 1MB.



38
39
40
41
# File 'lib/dynomite/item/query/relation/chain.rb', line 38

def limit(value)
  @query[:limit] = value
  self
end

#not(args = {}) ⇒ Object



15
16
17
18
# File 'lib/dynomite/item/query/relation/chain.rb', line 15

def not(args={})
  @query[:where] << WhereGroup.new(self, args, not: true)
  self
end

#or(args = {}) ⇒ Object



10
11
12
13
# File 'lib/dynomite/item/query/relation/chain.rb', line 10

def or(args={})
  @query[:where] << WhereGroup.new(self, args, or: true)
  self
end

#project(*fields) ⇒ Object Also known as: projection_expression

Product.where(category: “Electronics”).project(“id, category”).first



44
45
46
47
# File 'lib/dynomite/item/query/relation/chain.rb', line 44

def project(*fields)
  @query[:projection_expression] = fields
  self
end

#scan_index_backward(value = true) ⇒ Object



32
33
34
# File 'lib/dynomite/item/query/relation/chain.rb', line 32

def scan_index_backward(value=true)
  scan_index_forward(!value)
end

#scan_index_forward(value = true) ⇒ Object



27
28
29
30
# File 'lib/dynomite/item/query/relation/chain.rb', line 27

def scan_index_forward(value=true)
  @query[:scan_index_forward] = value
  self
end

#size_fn(path, size) ⇒ Object



120
121
122
123
# File 'lib/dynomite/item/query/relation/chain.rb', line 120

def size_fn(path, size)
  @query[:size_fn] << {path: path, size: size}
  self
end

#warn_on_scan(value = true) ⇒ Object



88
89
90
91
# File 'lib/dynomite/item/query/relation/chain.rb', line 88

def warn_on_scan(value=true)
  @warn_on_scan = value
  self
end

#where(args = {}) ⇒ Object Also known as: and



4
5
6
7
# File 'lib/dynomite/item/query/relation/chain.rb', line 4

def where(args={})
  @query[:where] << WhereGroup.new(self, args)
  self
end