dynamodb-api 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16f900dc71434dc863618388c16fa5be76331abca5b6c2118c3480e71534ce73
4
- data.tar.gz: 83749f39eb681e7ca6ab0fcccd158d7a15aa2da057bfdb382ba58b394439e2a5
3
+ metadata.gz: d9be0f31417b188293408482f8661646b207c587e62f19b252cba0beecb9f7a7
4
+ data.tar.gz: e449872d243d29819b761edf6503f5931cd838436eabb2584bd7ea238125573f
5
5
  SHA512:
6
- metadata.gz: 9787ae90fc9fc3d44f025a50387c5b1e3f835ff15e283537124344a449fd123d235ed82e0ff21ab960ca109346b06f29cb50bfde9273dce7f2ae6de814bf41ce
7
- data.tar.gz: a898013df6f194195b489e958b34126b286ae5c83d214b6faa513dacc89d5b198568a92fa9aa42bef693bdd3439f12e54424f7e8006166e43683822962c6f44e
6
+ metadata.gz: 43976f0890badbe08057345c9576d6cb48cd623ac97b1363bab6cc9dfaa245cded0cba11dc694a6d4213e0b08ab30ac8436f86b249553859220cb03224068ffa
7
+ data.tar.gz: 66be89216803aeb7644a12a5107894cc1531eb14c9ca70bae8dc304fdeffd985d1ba4ac83d8ff07eaa381138e51e4b90c8aa22f056c4e62e55ec21fce12a43fc
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [Unreleased]
8
+
9
+ ## [0.6.2] - 2018-12-13
10
+ ### Added
11
+ - [#32](https://github.com/walkersumida/dynamodb-api/pull/32) `remove_attributes` method
12
+
7
13
  ## [0.6.1] - 2018-11-22
8
14
  ### Added
9
15
  - [#30](https://github.com/walkersumida/dynamodb-api/pull/30) `retry_limit` option(default: 10)
data/README.md CHANGED
@@ -176,6 +176,23 @@ key = { id: '5' }
176
176
  Dynamodb::Api.delete('cars', key)
177
177
  ```
178
178
 
179
+ ### Remove attributes
180
+
181
+ ```ruby
182
+ key = { id: '3' }
183
+ attributes = ['status']
184
+ Dynamodb::Api.remove_attributes('cars', key, attributes)
185
+
186
+ query = Dynamodb::Api.query
187
+ query.from('cars').index('index_maker_id_release_date').
188
+ where(['maker_id', '=', 3])
189
+ items = query.all.items
190
+ ```
191
+
192
+ | id | maker_id(Partition key) | model | release_date(Sort key) |
193
+ |:---|:---|:---|:---|
194
+ |3 |3 |Model S |0.20120601e8 |
195
+
179
196
  ### Other API operations
180
197
 
181
198
  `client` returns the `<Aws::DynamoDB::Client>` .
@@ -20,7 +20,9 @@ require 'dynamodb/api/put/item'
20
20
  require 'dynamodb/api/delete/tables'
21
21
  require 'dynamodb/api/delete/item'
22
22
  require 'dynamodb/api/map/operator'
23
+ require 'dynamodb/api/update/base'
23
24
  require 'dynamodb/api/update/item'
25
+ require 'dynamodb/api/update/attributes'
24
26
 
25
27
  module Dynamodb
26
28
  module Api # :nodoc:
@@ -54,5 +56,9 @@ module Dynamodb
54
56
  def delete(table_name, key)
55
57
  Delete::Item.delete_item(key, table_name)
56
58
  end
59
+
60
+ def remove_attributes(table_name, key, attrs)
61
+ Update::Attributes.new.remove_attributes(key, attrs, table_name)
62
+ end
57
63
  end
58
64
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dynamodb
4
+ module Api
5
+ module Update
6
+ class Attributes < Base # :nodoc:
7
+ def remove_attributes(key, cols, table_name)
8
+ update_item(key, cols, table_name)
9
+ end
10
+
11
+ private
12
+
13
+ def build_update_expression
14
+ str = @cols.each_with_object([]) do |k, ary|
15
+ ary << "##{k}"
16
+ end.join(', ')
17
+ "REMOVE #{str}"
18
+ end
19
+
20
+ def build_expression_attribute_names
21
+ @cols.each_with_object({}) do |k, h|
22
+ h["##{k}"] = k
23
+ end
24
+ end
25
+
26
+ def build_update_clause
27
+ {
28
+ key: @key, table_name: @table_name,
29
+ update_expression: build_update_expression,
30
+ expression_attribute_names: build_expression_attribute_names,
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dynamodb
4
+ module Api
5
+ module Update
6
+ class Base # :nodoc:
7
+ def update_item(key, cols, table_name)
8
+ @key = key
9
+ @cols = cols
10
+ @table_name = table_name
11
+
12
+ client = Adapter.client
13
+ client.update_item(build_update_clause)
14
+ end
15
+
16
+ private
17
+
18
+ def build_update_expression
19
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
20
+ end
21
+
22
+ def build_expression_attribute_names
23
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
24
+ end
25
+
26
+ def build_expression_attribute_values
27
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
28
+ end
29
+
30
+ def build_update_clause
31
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -3,14 +3,9 @@
3
3
  module Dynamodb
4
4
  module Api
5
5
  module Update
6
- class Item # :nodoc:
6
+ class Item < Base # :nodoc:
7
7
  def update_item(key, cols, table_name)
8
- @key = key
9
- @cols = cols
10
- @table_name = table_name
11
-
12
- client = Adapter.client
13
- client.update_item(build_update_clause)
8
+ super(key, cols, table_name)
14
9
  end
15
10
 
16
11
  private
@@ -1,5 +1,5 @@
1
1
  module Dynamodb
2
2
  module Api
3
- VERSION = '0.6.1'.freeze
3
+ VERSION = '0.6.2'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - WalkerSumida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2018-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -167,6 +167,8 @@ files:
167
167
  - lib/dynamodb/api/relation/query_methods.rb
168
168
  - lib/dynamodb/api/relation/select_clause.rb
169
169
  - lib/dynamodb/api/relation/where_clause.rb
170
+ - lib/dynamodb/api/update/attributes.rb
171
+ - lib/dynamodb/api/update/base.rb
170
172
  - lib/dynamodb/api/update/item.rb
171
173
  - lib/dynamodb/api/version.rb
172
174
  homepage: https://github.com/walkersumida/dynamodb-api