dynamodb-api 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +17 -0
- data/lib/dynamodb/api.rb +6 -0
- data/lib/dynamodb/api/base.rb +50 -0
- data/lib/dynamodb/api/query.rb +1 -28
- data/lib/dynamodb/api/scan.rb +31 -0
- data/lib/dynamodb/api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbaea71109e5f59f3371de8c33d10a26e23855e6666c6e71d4c3fe46cd6f9818
|
4
|
+
data.tar.gz: 58b5b94c50002c02605e46eb75aeec66a2f8f38339f34d074fa23d16cf13f80d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba6e2154406a24eec7aa3a806b5901c6216c2cfa3f74ea00ded9c0849b8e272933d8f4bd92d2b20417e284815273046a1eb575cab7765e7eb6523493ea204c8
|
7
|
+
data.tar.gz: a31a6a368d48914534eb50d9055a6d6b6fa1ee3ae3edb95039f189caf047b635612f798ad012b32afa6c48c26d4e21025b57eeb193c683ad43bbd1a84de2717d
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.7.0] - 2018-12-23
|
10
|
+
### Added
|
11
|
+
- [#34](https://github.com/walkersumida/dynamodb-api/pull/34) `scan` method
|
12
|
+
|
9
13
|
## [0.6.2] - 2018-12-13
|
10
14
|
### Added
|
11
15
|
- [#32](https://github.com/walkersumida/dynamodb-api/pull/32) `remove_attributes` method
|
data/README.md
CHANGED
@@ -57,6 +57,23 @@ cars table.
|
|
57
57
|
|3 |3 |Model S |0.20120601e8 |0 |
|
58
58
|
|4 |1 |S2000 |0.19980101e8 |1 |
|
59
59
|
|
60
|
+
### Scan
|
61
|
+
|
62
|
+
Scan returns items in random order.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
scan = Dynamodb::Api.scan
|
66
|
+
scan.from('cars')
|
67
|
+
items = scan.all.items
|
68
|
+
```
|
69
|
+
|
70
|
+
| id | maker_id(Partition key) | model | release_date(Sort key) | status |
|
71
|
+
|:---|:---|:---|:---|:---|
|
72
|
+
|1 |1 |Accord |0.19760508e8 |0 |
|
73
|
+
|2 |2 |CROWN |0.19550101e8 |0 |
|
74
|
+
|3 |3 |Model S |0.20120601e8 |0 |
|
75
|
+
|4 |1 |S2000 |0.19980101e8 |1 |
|
76
|
+
|
60
77
|
### Query
|
61
78
|
https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method
|
62
79
|
|
data/lib/dynamodb/api.rb
CHANGED
@@ -5,7 +5,9 @@ require 'active_support/core_ext'
|
|
5
5
|
require 'dynamodb/api/version'
|
6
6
|
require 'dynamodb/api/config'
|
7
7
|
require 'dynamodb/api/adapter'
|
8
|
+
require 'dynamodb/api/base'
|
8
9
|
require 'dynamodb/api/query'
|
10
|
+
require 'dynamodb/api/scan'
|
9
11
|
require 'dynamodb/api/relation'
|
10
12
|
require 'dynamodb/api/relation/query_methods'
|
11
13
|
require 'dynamodb/api/relation/from_clause'
|
@@ -40,6 +42,10 @@ module Dynamodb
|
|
40
42
|
Delete::Tables.delete_tables
|
41
43
|
end
|
42
44
|
|
45
|
+
def scan
|
46
|
+
Scan.new
|
47
|
+
end
|
48
|
+
|
43
49
|
def query
|
44
50
|
Query.new
|
45
51
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dynamodb/api/relation'
|
4
|
+
|
5
|
+
module Dynamodb
|
6
|
+
module Api
|
7
|
+
class Base # :nodoc:
|
8
|
+
include Relation
|
9
|
+
|
10
|
+
def all
|
11
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def build_query
|
17
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def base_params
|
21
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def order_direct(clause)
|
25
|
+
clause&.direct ? clause.direct : OrderClause.new.direct
|
26
|
+
end
|
27
|
+
|
28
|
+
def select_name(clause)
|
29
|
+
clause&.name ? clause.name : SelectClause.new.name
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_filter_clause
|
33
|
+
return {} if filter_clause&.expression.blank?
|
34
|
+
{
|
35
|
+
filter_expression: filter_clause.expression,
|
36
|
+
expression_attribute_values: filter_clause.values,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_expression_attribute_names(params)
|
41
|
+
if filter_clause&.reserved_words.present?
|
42
|
+
expression_attribute.add(filter_clause.reserved_words)
|
43
|
+
end
|
44
|
+
if expression_attribute.names.present?
|
45
|
+
params[:expression_attribute_names] = expression_attribute.names
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/dynamodb/api/query.rb
CHANGED
@@ -4,9 +4,7 @@ require 'dynamodb/api/relation'
|
|
4
4
|
|
5
5
|
module Dynamodb
|
6
6
|
module Api
|
7
|
-
class Query # :nodoc:
|
8
|
-
include Relation
|
9
|
-
|
7
|
+
class Query < Base # :nodoc:
|
10
8
|
def all
|
11
9
|
Adapter.client.query(build_query)
|
12
10
|
end
|
@@ -29,31 +27,6 @@ module Dynamodb
|
|
29
27
|
key_conditions: where_clause.key_conditions,
|
30
28
|
}
|
31
29
|
end
|
32
|
-
|
33
|
-
def order_direct(clause)
|
34
|
-
clause&.direct ? clause.direct : OrderClause.new.direct
|
35
|
-
end
|
36
|
-
|
37
|
-
def select_name(clause)
|
38
|
-
clause&.name ? clause.name : SelectClause.new.name
|
39
|
-
end
|
40
|
-
|
41
|
-
def build_filter_clause
|
42
|
-
return {} if filter_clause&.expression.blank?
|
43
|
-
{
|
44
|
-
filter_expression: filter_clause.expression,
|
45
|
-
expression_attribute_values: filter_clause.values,
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def build_expression_attribute_names(params)
|
50
|
-
if filter_clause&.reserved_words.present?
|
51
|
-
expression_attribute.add(filter_clause.reserved_words)
|
52
|
-
end
|
53
|
-
if expression_attribute.names.present?
|
54
|
-
params[:expression_attribute_names] = expression_attribute.names
|
55
|
-
end
|
56
|
-
end
|
57
30
|
end
|
58
31
|
end
|
59
32
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dynamodb/api/relation'
|
4
|
+
|
5
|
+
module Dynamodb
|
6
|
+
module Api
|
7
|
+
class Scan < Base # :nodoc:
|
8
|
+
def all
|
9
|
+
Adapter.client.scan(build_query)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def build_query
|
15
|
+
build_params = base_params.merge(build_filter_clause)
|
16
|
+
build_params[:index_name] = index_clause.name if index_clause&.name
|
17
|
+
build_params[:key_conditions] = where_clause.key_conditions if where_clause&.key_conditions
|
18
|
+
build_params[:select] = select_name(select_clause)
|
19
|
+
build_expression_attribute_names(build_params)
|
20
|
+
build_params[:limit] = limit_clause.number if limit_clause&.number
|
21
|
+
build_params
|
22
|
+
end
|
23
|
+
|
24
|
+
def base_params
|
25
|
+
{
|
26
|
+
table_name: from_clause.name,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/dynamodb/api/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WalkerSumida
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- gemfiles/aws_sdk_3.gemfile
|
151
151
|
- lib/dynamodb/api.rb
|
152
152
|
- lib/dynamodb/api/adapter.rb
|
153
|
+
- lib/dynamodb/api/base.rb
|
153
154
|
- lib/dynamodb/api/config.rb
|
154
155
|
- lib/dynamodb/api/config/options.rb
|
155
156
|
- lib/dynamodb/api/delete/item.rb
|
@@ -167,6 +168,7 @@ files:
|
|
167
168
|
- lib/dynamodb/api/relation/query_methods.rb
|
168
169
|
- lib/dynamodb/api/relation/select_clause.rb
|
169
170
|
- lib/dynamodb/api/relation/where_clause.rb
|
171
|
+
- lib/dynamodb/api/scan.rb
|
170
172
|
- lib/dynamodb/api/update/attributes.rb
|
171
173
|
- lib/dynamodb/api/update/base.rb
|
172
174
|
- lib/dynamodb/api/update/item.rb
|