dynamo_record 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/dynamo_record/fields.rb +3 -3
- data/lib/dynamo_record/query.rb +17 -0
- data/lib/dynamo_record/version.rb +1 -1
- data/spec/dynamo_record/query_spec.rb +13 -0
- data/spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_a_record_by_hash_key_and_range_key.yml +50 -0
- data/spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_all_records_by_hash_key.yml +50 -0
- data/spec/spec_helper.rb +2 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b849c11bb6edf1b5b8253df1fa040d92c69775b
|
4
|
+
data.tar.gz: 42857a91944bda388c706c89cf250274b76a7f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d5886affd59ca355e02fb40b92eee7cc4ea74846eeb7e7c81c64217bc8dcb1beb283d6776a7b0adc27996ce62a452f6561b7a3af19887cd054dcd3e7166dbdc
|
7
|
+
data.tar.gz: 2a5f30c5918971220cd20b99d22ed5ceb324418b4429c11ab5c13ec903e1177372f862143d6177cc7146b16ce30dee6e056dc90617764dbb4579616a666b3336
|
data/.gitignore
CHANGED
data/lib/dynamo_record/fields.rb
CHANGED
@@ -70,9 +70,9 @@ module DynamoRecord
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
def hash_key
|
74
|
+
:id # default hash key
|
75
|
+
end
|
76
76
|
|
77
77
|
def range_key
|
78
78
|
@range_key ||= self.attributes.select { |k,v| v[:options][:range_key] }.keys.first rescue nil
|
data/lib/dynamo_record/query.rb
CHANGED
@@ -17,6 +17,7 @@ module DynamoRecord
|
|
17
17
|
key_conditions = {}
|
18
18
|
key_conditions[attribute] = { attribute_value_list: [value],
|
19
19
|
comparison_operator: 'EQ' }
|
20
|
+
|
20
21
|
index_name = "#{attribute}-index"
|
21
22
|
options = self.default_options
|
22
23
|
options.merge!(key_conditions: key_conditions, index_name: index_name)
|
@@ -24,6 +25,22 @@ module DynamoRecord
|
|
24
25
|
response = self.client.query(options)
|
25
26
|
DynamoRecord::Collection.new(response, self)
|
26
27
|
end
|
28
|
+
|
29
|
+
def find_by_hash_and_range(hash_key, range_key=nil)
|
30
|
+
key_conditions = {}
|
31
|
+
key_conditions[self.hash_key] = { attribute_value_list: [hash_key],
|
32
|
+
comparison_operator: 'EQ' }
|
33
|
+
if range_key
|
34
|
+
key_conditions[self.range_key] = { attribute_value_list: [range_key],
|
35
|
+
comparison_operator: 'EQ' }
|
36
|
+
end
|
37
|
+
|
38
|
+
options = self.default_options
|
39
|
+
options.merge!(key_conditions: key_conditions)
|
40
|
+
|
41
|
+
response = self.client.query(options)
|
42
|
+
DynamoRecord::Collection.new(response, self)
|
43
|
+
end
|
27
44
|
end
|
28
45
|
end
|
29
46
|
end
|
@@ -42,6 +42,19 @@ RSpec.describe DynamoRecord::Query, :vcr do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe 'querying' do
|
45
|
+
|
46
|
+
describe '#find_by_hash_and_range' do
|
47
|
+
it 'returns a record by hash key and range key' do
|
48
|
+
person = PersonRange.find_by_hash_and_range('1', '2015-01-28T14:37:01+08:00')
|
49
|
+
expect(person.count).to eq(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns all records by hash key' do
|
53
|
+
people = PersonRange.find_by_hash_and_range('1')
|
54
|
+
expect(people.count).to eq(2)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
45
58
|
describe '#where' do
|
46
59
|
it 'queries by condition' do
|
47
60
|
people = Person.where(name: 'Person 2')
|
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://dynamodb.us-east-1.amazonaws.com/
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"TableName":"person_ranges","KeyConditions":{"id":{"AttributeValueList":[{"S":"1"}],"ComparisonOperator":"EQ"},"created_at":{"AttributeValueList":[{"S":"2015-01-28T14:37:01+08:00"}],"ComparisonOperator":"EQ"}}}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/x-amz-json-1.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- ''
|
14
|
+
User-Agent:
|
15
|
+
- aws-sdk-ruby2/2.0.21 ruby/2.1.2 x86_64-darwin14.0
|
16
|
+
X-Amz-Target:
|
17
|
+
- DynamoDB_20120810.Query
|
18
|
+
X-Amz-Date:
|
19
|
+
- 20150130T064846Z
|
20
|
+
X-Amz-Content-Sha256:
|
21
|
+
- cb65882116db16faf18fa6cfb02eb793e9952156441a23509c56b3dcc37abd33
|
22
|
+
Authorization:
|
23
|
+
- AWS4-HMAC-SHA256 Credential=key/20150130/us-east-1/dynamodb/aws4_request,
|
24
|
+
SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-target,
|
25
|
+
Signature=499914a63276dd30775dfba66cfde46cc359679fdc6434d9bcdfe7193e487720
|
26
|
+
Content-Length:
|
27
|
+
- '211'
|
28
|
+
Accept:
|
29
|
+
- "*/*"
|
30
|
+
response:
|
31
|
+
status:
|
32
|
+
code: 200
|
33
|
+
message: OK
|
34
|
+
headers:
|
35
|
+
X-Amzn-Requestid:
|
36
|
+
- GN2UG13P0SNIKC2RF5OKIH5JTJVV4KQNSO5AEMVJF66Q9ASUAAJG
|
37
|
+
X-Amz-Crc32:
|
38
|
+
- '4076139363'
|
39
|
+
Content-Type:
|
40
|
+
- application/x-amz-json-1.0
|
41
|
+
Content-Length:
|
42
|
+
- '102'
|
43
|
+
Date:
|
44
|
+
- Fri, 30 Jan 2015 06:48:48 GMT
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"Count":1,"Items":[{"created_at":{"S":"2015-01-28T14:37:01+08:00"},"id":{"S":"1"}}],"ScannedCount":1}'
|
48
|
+
http_version:
|
49
|
+
recorded_at: Fri, 30 Jan 2015 06:48:49 GMT
|
50
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://dynamodb.us-east-1.amazonaws.com/
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"TableName":"person_ranges","KeyConditions":{"id":{"AttributeValueList":[{"S":"1"}],"ComparisonOperator":"EQ"}}}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/x-amz-json-1.0
|
12
|
+
Accept-Encoding:
|
13
|
+
- ''
|
14
|
+
User-Agent:
|
15
|
+
- aws-sdk-ruby2/2.0.21 ruby/2.1.2 x86_64-darwin14.0
|
16
|
+
X-Amz-Target:
|
17
|
+
- DynamoDB_20120810.Query
|
18
|
+
X-Amz-Date:
|
19
|
+
- 20150130T064849Z
|
20
|
+
X-Amz-Content-Sha256:
|
21
|
+
- f04e6fb149222c33132f14b3dd507d21d3deae8d7d2458d4bfd9466dfc628bbb
|
22
|
+
Authorization:
|
23
|
+
- AWS4-HMAC-SHA256 Credential=key/20150130/us-east-1/dynamodb/aws4_request,
|
24
|
+
SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-target,
|
25
|
+
Signature=24eb78d623265f915ae3567662a823c5ad3401f27a63467a96a7a6d4eb3dc042
|
26
|
+
Content-Length:
|
27
|
+
- '113'
|
28
|
+
Accept:
|
29
|
+
- "*/*"
|
30
|
+
response:
|
31
|
+
status:
|
32
|
+
code: 200
|
33
|
+
message: OK
|
34
|
+
headers:
|
35
|
+
X-Amzn-Requestid:
|
36
|
+
- 3PN8EO8AOFQ287VT9AB45UUPV7VV4KQNSO5AEMVJF66Q9ASUAAJG
|
37
|
+
X-Amz-Crc32:
|
38
|
+
- '2876920674'
|
39
|
+
Content-Type:
|
40
|
+
- application/x-amz-json-1.0
|
41
|
+
Content-Length:
|
42
|
+
- '166'
|
43
|
+
Date:
|
44
|
+
- Fri, 30 Jan 2015 06:48:49 GMT
|
45
|
+
body:
|
46
|
+
encoding: UTF-8
|
47
|
+
string: '{"Count":2,"Items":[{"created_at":{"S":"2015-01-28T14:37:01+08:00"},"id":{"S":"1"}},{"created_at":{"S":"2015-01-29T14:36:59+08:00"},"id":{"S":"1"}}],"ScannedCount":2}'
|
48
|
+
http_version:
|
49
|
+
recorded_at: Fri, 30 Jan 2015 06:48:50 GMT
|
50
|
+
recorded_with: VCR 2.9.3
|
data/spec/spec_helper.rb
CHANGED
@@ -13,6 +13,6 @@ VCR.configure do |c|
|
|
13
13
|
end
|
14
14
|
|
15
15
|
DynamoRecord.configure do |config|
|
16
|
-
config.access_key_id = 'key'
|
17
|
-
config.secret_access_key = 'secret'
|
16
|
+
config.access_key_id = ENV['DYNAMODB_KEY'] || 'key'
|
17
|
+
config.secret_access_key = ENV['DYNAMODB_SECRET'] || 'secret'
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamo_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nguyen Vu Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -161,6 +161,8 @@ files:
|
|
161
161
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_all/pagination/navigates_to_next_page.yml
|
162
162
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_all/pagination/tells_if_there_is_a_next_page.yml
|
163
163
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_query/queries_by_condition.yml
|
164
|
+
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_a_record_by_hash_key_and_range_key.yml
|
165
|
+
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_all_records_by_hash_key.yml
|
164
166
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/queries_by_condition.yml
|
165
167
|
- spec/spec_helper.rb
|
166
168
|
homepage: https://github.com/yetanothernguyen/dynamo_record
|
@@ -219,5 +221,7 @@ test_files:
|
|
219
221
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_all/pagination/navigates_to_next_page.yml
|
220
222
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_all/pagination/tells_if_there_is_a_next_page.yml
|
221
223
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/_query/queries_by_condition.yml
|
224
|
+
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_a_record_by_hash_key_and_range_key.yml
|
225
|
+
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_all_records_by_hash_key.yml
|
222
226
|
- spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/queries_by_condition.yml
|
223
227
|
- spec/spec_helper.rb
|