dynamodb-api 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +2 -0
- data/.travis.yml +5 -1
- data/Gemfile.lock +24 -1
- data/README.md +100 -5
- data/dynamodb-api.gemspec +3 -2
- data/lib/dynamodb/api.rb +2 -0
- data/lib/dynamodb/api/adapter.rb +1 -1
- data/lib/dynamodb/api/map/operator.rb +29 -0
- data/lib/dynamodb/api/query.rb +3 -2
- data/lib/dynamodb/api/relation.rb +1 -0
- data/lib/dynamodb/api/relation/expression_attribute_names.rb +1 -2
- data/lib/dynamodb/api/relation/global_secondary_index.rb +1 -1
- data/lib/dynamodb/api/relation/limit_clause.rb +15 -0
- data/lib/dynamodb/api/relation/query_methods.rb +35 -28
- data/lib/dynamodb/api/relation/where_clause.rb +3 -3
- data/lib/dynamodb/api/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3497adfb9b42e61ab127deb44c26834aff181ebe8a12e2842a49f4548f87b844
|
4
|
+
data.tar.gz: 9bdbb77d400193f402ae5e02502d2cd02ef39eee12f0455325b1f0bd1673c930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab22702e4ee21d4471a499a743bd99f15e9a2e231adbce737db77feb1c405e18ceed4ab833f602b135051a7fede6f5b1bd85ca7caba736bc5b88cb031e827999
|
7
|
+
data.tar.gz: 070f875b3e41688a0840ec506a3f12b04127e59d0dec90d2102e50abad14cdd742a6fccc7b274813065b9226330dc13f176d02c7144d586a57603c9df2c9d4a6
|
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
data/.travis.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.3
|
5
|
+
- 2.4
|
6
|
+
- 2.5
|
5
7
|
before_install: gem install bundler -v 1.16.2
|
6
8
|
|
7
9
|
before_script:
|
8
10
|
- docker-compose up -d
|
9
11
|
|
12
|
+
script: bundle exec rubocop --fail-level=C
|
13
|
+
|
10
14
|
after_script:
|
11
15
|
- docker-compose down
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamodb-api (0.4.
|
4
|
+
dynamodb-api (0.4.2)
|
5
5
|
activesupport (>= 4)
|
6
6
|
aws-sdk (~> 2)
|
7
7
|
|
@@ -13,6 +13,7 @@ GEM
|
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
|
+
ast (2.4.0)
|
16
17
|
aws-sdk (2.11.93)
|
17
18
|
aws-sdk-resources (= 2.11.93)
|
18
19
|
aws-sdk-core (2.11.93)
|
@@ -27,15 +28,21 @@ GEM
|
|
27
28
|
diff-lcs (1.3)
|
28
29
|
i18n (1.0.1)
|
29
30
|
concurrent-ruby (~> 1.0)
|
31
|
+
jaro_winkler (1.5.1)
|
30
32
|
jmespath (1.4.0)
|
31
33
|
method_source (0.9.0)
|
32
34
|
minitest (5.11.3)
|
35
|
+
parallel (1.12.1)
|
36
|
+
parser (2.5.1.2)
|
37
|
+
ast (~> 2.4.0)
|
38
|
+
powerpack (0.1.2)
|
33
39
|
pry (0.11.3)
|
34
40
|
coderay (~> 1.1.0)
|
35
41
|
method_source (~> 0.9.0)
|
36
42
|
pry-byebug (3.6.0)
|
37
43
|
byebug (~> 10.0)
|
38
44
|
pry (~> 0.10)
|
45
|
+
rainbow (3.0.0)
|
39
46
|
rake (10.5.0)
|
40
47
|
rspec (3.7.0)
|
41
48
|
rspec-core (~> 3.7.0)
|
@@ -50,9 +57,24 @@ GEM
|
|
50
57
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
58
|
rspec-support (~> 3.7.0)
|
52
59
|
rspec-support (3.7.1)
|
60
|
+
rubocop (0.57.2)
|
61
|
+
jaro_winkler (~> 1.5.1)
|
62
|
+
parallel (~> 1.10)
|
63
|
+
parser (>= 2.5)
|
64
|
+
powerpack (~> 0.1)
|
65
|
+
rainbow (>= 2.2.2, < 4.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
68
|
+
rubocop-airbnb (1.5.0)
|
69
|
+
rubocop (= 0.57.2)
|
70
|
+
rubocop-rspec (= 1.27.0)
|
71
|
+
rubocop-rspec (1.27.0)
|
72
|
+
rubocop (>= 0.56.0)
|
73
|
+
ruby-progressbar (1.10.0)
|
53
74
|
thread_safe (0.3.6)
|
54
75
|
tzinfo (1.2.5)
|
55
76
|
thread_safe (~> 0.1)
|
77
|
+
unicode-display_width (1.4.0)
|
56
78
|
|
57
79
|
PLATFORMS
|
58
80
|
ruby
|
@@ -64,6 +86,7 @@ DEPENDENCIES
|
|
64
86
|
pry-byebug
|
65
87
|
rake (~> 10.0)
|
66
88
|
rspec (~> 3.0)
|
89
|
+
rubocop-airbnb
|
67
90
|
|
68
91
|
BUNDLED WITH
|
69
92
|
1.16.2
|
data/README.md
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
# Dynamodb::Api
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/walkersumida/dynamodb-api.svg?branch=master)](https://travis-ci.org/walkersumida/dynamodb-api)
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dynamodb/api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
-
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/dynamodb-api.svg)](https://badge.fury.io/rb/dynamodb-api)
|
8
5
|
|
9
6
|
## Installation
|
10
7
|
|
@@ -24,9 +21,11 @@ Or install it yourself as:
|
|
24
21
|
|
25
22
|
## Configuration
|
26
23
|
|
24
|
+
### Rails
|
25
|
+
|
27
26
|
`config/initializers/dynamodb_api.rb`
|
28
27
|
|
29
|
-
```
|
28
|
+
```ruby
|
30
29
|
Dynamodb::Api.config do |config|
|
31
30
|
config.access_key_id = ''
|
32
31
|
config.secret_access_key = ''
|
@@ -36,6 +35,102 @@ Dynamodb::Api.config do |config|
|
|
36
35
|
end
|
37
36
|
```
|
38
37
|
|
38
|
+
### Other
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
Dynamodb::Api.config.access_key_id = ''
|
42
|
+
Dynamodb::Api.config.secret_access_key = ''
|
43
|
+
Dynamodb::Api.config.region = ''
|
44
|
+
Dynamodb::Api.config.table_name_prefix = ''
|
45
|
+
Dynamodb::Api.config.index_name_prefix = ''
|
46
|
+
```
|
47
|
+
|
48
|
+
## How to use
|
49
|
+
e.g.
|
50
|
+
|
51
|
+
cars table.
|
52
|
+
|
53
|
+
| maker_id(Partition key) | model | release_date(Sort key) |
|
54
|
+
|:---|:---|:---|
|
55
|
+
|1 |Accord |0.19760508e8 |
|
56
|
+
|2 |CROWN |0.19550101e8 |
|
57
|
+
|3 |Model S |0.20120601e8 |
|
58
|
+
|1 |S2000 |0.19980101e8 |
|
59
|
+
|
60
|
+
### Query
|
61
|
+
https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method
|
62
|
+
|
63
|
+
#### Partition(Hash) key
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
query = Dynamodb::Api::Query.new
|
67
|
+
query.from('cars').index('index_maker_id_release_date').
|
68
|
+
where(['maker_id', '=', 1])
|
69
|
+
items = query.all.items
|
70
|
+
```
|
71
|
+
|
72
|
+
| maker_id | model | release_date |
|
73
|
+
|:---|:---|:---|
|
74
|
+
|1 |S2000 |0.19980101e8 |
|
75
|
+
|1 |Accord |0.19760508e8 |
|
76
|
+
|
77
|
+
#### Partition key and Sort(Range) key
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
query = Dynamodb::Api::Query.new
|
81
|
+
query.from('cars').index('index_maker_id_release_date').
|
82
|
+
where([['maker_id', '=', 1], ['release_date', '>=', 19_980_101]])
|
83
|
+
items = query.all.items
|
84
|
+
```
|
85
|
+
|
86
|
+
| maker_id | model | release_date |
|
87
|
+
|:---|:---|:---|
|
88
|
+
|1 |S2000 |0.19980101e8 |
|
89
|
+
|
90
|
+
#### Sorting
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
query = Dynamodb::Api::Query.new
|
94
|
+
query.from('cars').index('index_maker_id_release_date').
|
95
|
+
where(['maker_id', '=', 1]).
|
96
|
+
order('asc') # default: 'desc'
|
97
|
+
items = query.all.items
|
98
|
+
```
|
99
|
+
|
100
|
+
| maker_id | model | release_date |
|
101
|
+
|:---|:---|:---|
|
102
|
+
|1 |Accord |0.19760508e8 |
|
103
|
+
|1 |S2000 |0.19980101e8 |
|
104
|
+
|
105
|
+
#### Filter
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
query = Dynamodb::Api::Query.new
|
109
|
+
query.from('cars').index('index_maker_id_release_date').
|
110
|
+
where(['maker_id', '=', 1]).
|
111
|
+
filter('model = :model', ':model': 'S2000')
|
112
|
+
items = query.all.items
|
113
|
+
```
|
114
|
+
|
115
|
+
| maker_id | model | release_date |
|
116
|
+
|:---|:---|:---|
|
117
|
+
|1 |S2000 |0.19980101e8 |
|
118
|
+
|
119
|
+
#### Limit
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
query = Dynamodb::Api::Query.new
|
123
|
+
query.from('cars').index('index_maker_id_release_date').
|
124
|
+
where(['maker_id', '=', 1]).
|
125
|
+
order('asc'). # default: 'desc'
|
126
|
+
limit(1)
|
127
|
+
items = query.all.items
|
128
|
+
```
|
129
|
+
|
130
|
+
| maker_id | model | release_date |
|
131
|
+
|:---|:---|:---|
|
132
|
+
|1 |Accord |0.19760508e8 |
|
133
|
+
|
39
134
|
## Development
|
40
135
|
|
41
136
|
- Run `docker-compose up` to run the dynamodb_local.
|
data/dynamodb-api.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['WalkerSumida']
|
9
9
|
spec.email = ['walkersumida@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = %q
|
12
|
-
spec.description = %q
|
11
|
+
spec.summary = %q(aws dynamodb api)
|
12
|
+
spec.description = %q(aws dynamodb api)
|
13
13
|
spec.homepage = 'https://github.com/walkersumida/dynamodb-api'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency 'rake', '~> 10.0'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
31
|
spec.add_development_dependency 'pry'
|
32
|
+
spec.add_development_dependency 'rubocop-airbnb'
|
32
33
|
end
|
data/lib/dynamodb/api.rb
CHANGED
@@ -14,8 +14,10 @@ require 'dynamodb/api/relation/where_clause'
|
|
14
14
|
require 'dynamodb/api/relation/filter_clause'
|
15
15
|
require 'dynamodb/api/relation/global_secondary_index'
|
16
16
|
require 'dynamodb/api/relation/expression_attribute_names'
|
17
|
+
require 'dynamodb/api/relation/limit_clause'
|
17
18
|
require 'dynamodb/api/put/item'
|
18
19
|
require 'dynamodb/api/delete/tables'
|
20
|
+
require 'dynamodb/api/map/operator'
|
19
21
|
|
20
22
|
module Dynamodb
|
21
23
|
module Api # :nodoc:
|
data/lib/dynamodb/api/adapter.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dynamodb
|
4
|
+
module Api
|
5
|
+
module Map
|
6
|
+
class Operator # :nodoc:
|
7
|
+
def self.key(k)
|
8
|
+
k = k.gsub(' ', '')
|
9
|
+
case k
|
10
|
+
when '='
|
11
|
+
'EQ'
|
12
|
+
when '!='
|
13
|
+
'NE'
|
14
|
+
when '<='
|
15
|
+
'LE'
|
16
|
+
when '<'
|
17
|
+
'LT'
|
18
|
+
when '>='
|
19
|
+
'GE'
|
20
|
+
when '>'
|
21
|
+
'GT'
|
22
|
+
else
|
23
|
+
k
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/dynamodb/api/query.rb
CHANGED
@@ -17,13 +17,14 @@ module Dynamodb
|
|
17
17
|
build_params = {
|
18
18
|
table_name: from_clause.name,
|
19
19
|
index_name: index_clause.name,
|
20
|
-
key_conditions: where_clause.key_conditions
|
20
|
+
key_conditions: where_clause.key_conditions,
|
21
21
|
}.merge(build_filter_clause)
|
22
22
|
build_params[:scan_index_forward] = order_direct(order_clause)
|
23
23
|
build_params[:select] = select_name(select_clause)
|
24
24
|
if expression_attribute&.names
|
25
25
|
build_params[:expression_attribute_names] = expression_attribute.names
|
26
26
|
end
|
27
|
+
build_params[:limit] = limit_clause.number if limit_clause&.number
|
27
28
|
build_params
|
28
29
|
end
|
29
30
|
|
@@ -39,7 +40,7 @@ module Dynamodb
|
|
39
40
|
return {} unless filter_clause&.expression
|
40
41
|
{
|
41
42
|
filter_expression: filter_clause.expression,
|
42
|
-
expression_attribute_values: filter_clause.values
|
43
|
+
expression_attribute_values: filter_clause.values,
|
43
44
|
}
|
44
45
|
end
|
45
46
|
end
|
@@ -2,40 +2,47 @@
|
|
2
2
|
|
3
3
|
module Dynamodb
|
4
4
|
module Api
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module Relation
|
6
|
+
module QueryMethods # :nodoc:
|
7
|
+
def from(value)
|
8
|
+
self.from_clause = Relation::FromClause.new(value)
|
9
|
+
self
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def index(value)
|
13
|
+
self.index_clause = Relation::GlobalSecondaryIndex.new(value)
|
14
|
+
self
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def select(value = nil)
|
18
|
+
self.select_clause = Relation::SelectClause.new(value)
|
19
|
+
self
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def order(value = nil)
|
23
|
+
self.order_clause = Relation::OrderClause.new(value)
|
24
|
+
self
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def where(key_conditions)
|
28
|
+
self.where_clause = Relation::WhereClause.new(key_conditions)
|
29
|
+
self
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def filter(expression, values)
|
33
|
+
self.filter_clause = Relation::FilterClause.new(expression, values)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def ex_attr(names)
|
38
|
+
self.expression_attribute = Relation::ExpressionAttributeNames.new(names)
|
39
|
+
self
|
40
|
+
end
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
42
|
+
def limit(value)
|
43
|
+
self.limit_clause = Relation::LimitClause.new(value)
|
44
|
+
self
|
45
|
+
end
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
@@ -7,8 +7,8 @@ module Dynamodb
|
|
7
7
|
attr_reader :key_conditions
|
8
8
|
|
9
9
|
KEY = 0
|
10
|
-
VALUE =
|
11
|
-
OPERATOR =
|
10
|
+
VALUE = 2
|
11
|
+
OPERATOR = 1
|
12
12
|
|
13
13
|
def initialize(key_conditions)
|
14
14
|
@key_conditions = build(key_conditions)
|
@@ -21,7 +21,7 @@ module Dynamodb
|
|
21
21
|
conditions.each_with_object({}) do |c, h|
|
22
22
|
h[c[KEY]] = {
|
23
23
|
attribute_value_list: format_value(c[VALUE]),
|
24
|
-
comparison_operator: c[OPERATOR]
|
24
|
+
comparison_operator: Map::Operator.key(c[OPERATOR]),
|
25
25
|
}
|
26
26
|
end
|
27
27
|
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.
|
4
|
+
version: 0.4.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
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-airbnb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: aws dynamodb api
|
98
112
|
email:
|
99
113
|
- walkersumida@gmail.com
|
@@ -104,6 +118,8 @@ files:
|
|
104
118
|
- ".gitignore"
|
105
119
|
- ".pryrc"
|
106
120
|
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".rubocop_todo.yml"
|
107
123
|
- ".travis.yml"
|
108
124
|
- CODE_OF_CONDUCT.md
|
109
125
|
- Gemfile
|
@@ -120,6 +136,7 @@ files:
|
|
120
136
|
- lib/dynamodb/api/config.rb
|
121
137
|
- lib/dynamodb/api/config/options.rb
|
122
138
|
- lib/dynamodb/api/delete/tables.rb
|
139
|
+
- lib/dynamodb/api/map/operator.rb
|
123
140
|
- lib/dynamodb/api/put/item.rb
|
124
141
|
- lib/dynamodb/api/query.rb
|
125
142
|
- lib/dynamodb/api/relation.rb
|
@@ -127,6 +144,7 @@ files:
|
|
127
144
|
- lib/dynamodb/api/relation/filter_clause.rb
|
128
145
|
- lib/dynamodb/api/relation/from_clause.rb
|
129
146
|
- lib/dynamodb/api/relation/global_secondary_index.rb
|
147
|
+
- lib/dynamodb/api/relation/limit_clause.rb
|
130
148
|
- lib/dynamodb/api/relation/order_clause.rb
|
131
149
|
- lib/dynamodb/api/relation/query_methods.rb
|
132
150
|
- lib/dynamodb/api/relation/select_clause.rb
|