Module: Dynorm::Query

Included in:
Client
Defined in:
lib/dynorm/query.rb

Instance Method Summary collapse

Instance Method Details

#find(hash = {}) ⇒ Object



40
41
42
43
# File 'lib/dynorm/query.rb', line 40

def find(hash = {})
  resp = query(hash)
  Item.new @table_config, resp.items.first
end

#get(key = {}) ⇒ Object



5
6
7
8
9
# File 'lib/dynorm/query.rb', line 5

def get(key = {})
  params = default_params.merge(key: item_key(key))

  db.get_item(params)
end

#put(item = {}) ⇒ Object



11
12
13
14
15
# File 'lib/dynorm/query.rb', line 11

def put(item = {})
  params = default_params.merge(item: item)
  resp = db.put_item(params)
  resp.attributes
end

#query(key, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/dynorm/query.rb', line 31

def query(key, options = {})
  exp = KeyExpression.new(key)

  params = default_params.merge(exp.params)
  params = params.merge(option_params(options)) if options.any?

  db.query(params)
end

#remove_attributes(key, *attrs) ⇒ Object



24
25
26
27
28
29
# File 'lib/dynorm/query.rb', line 24

def remove_attributes(key, *attrs)
  params = default_params.merge(key: item_key(key))
  params = params.merge(attribute_updates: remove_attribute_params(attrs))

  db.update_item(params)
end

#update(key, attrs) ⇒ Object



17
18
19
20
21
22
# File 'lib/dynorm/query.rb', line 17

def update(key, attrs)
  params = default_params.merge(key: item_key(key))
  params = params.merge(attribute_updates: update_attribute_params(attrs))

  db.update_item(params)
end

#where(key, options = {}) ⇒ Object



45
46
47
48
# File 'lib/dynorm/query.rb', line 45

def where(key, options = {})
  resp = query(key, options)
  ItemCollection.new @table_config, resp.items
end