dynamo_record 0.0.20 → 0.0.21

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
  SHA1:
3
- metadata.gz: 9b849c11bb6edf1b5b8253df1fa040d92c69775b
4
- data.tar.gz: 42857a91944bda388c706c89cf250274b76a7f76
3
+ metadata.gz: 04dcd3aca07812fad600169cb5a2cdf091b929c3
4
+ data.tar.gz: 9038222e5ae7bd0f4194c0a39d79b9799c4fd682
5
5
  SHA512:
6
- metadata.gz: 6d5886affd59ca355e02fb40b92eee7cc4ea74846eeb7e7c81c64217bc8dcb1beb283d6776a7b0adc27996ce62a452f6561b7a3af19887cd054dcd3e7166dbdc
7
- data.tar.gz: 2a5f30c5918971220cd20b99d22ed5ceb324418b4429c11ab5c13ec903e1177372f862143d6177cc7146b16ce30dee6e056dc90617764dbb4579616a666b3336
6
+ metadata.gz: bcdd857a014344fe36eab01004663f7bed7ee496d8d7cbd4238d323a2c8fd0c3ec4a5548a5968bbb64caa9b8a0b88b0e192130ffe10d82159a47b41cd4a33b97
7
+ data.tar.gz: cd46c302fb57db27b29bfb5539893738b3107dfb9dcae46479f802e64b3c306298db9019d1b0a644e2a6d60e112969f0f1b2f40f71fb9a68769141f6fac312aa
@@ -27,5 +27,9 @@ module DynamoRecord
27
27
  yield self.class.new(page, @klass)
28
28
  end
29
29
  end
30
+
31
+ def last_evaluated_key
32
+ @pager.last_evaluated_key
33
+ end
30
34
  end
31
35
  end
@@ -11,32 +11,20 @@ module DynamoRecord
11
11
  DynamoRecord::Collection.new(response, self)
12
12
  end
13
13
 
14
- def where(condition = {})
15
- attribute = condition.first.first.to_s
16
- value = condition.first.second
17
- key_conditions = {}
18
- key_conditions[attribute] = { attribute_value_list: [value],
19
- comparison_operator: 'EQ' }
20
-
21
- index_name = "#{attribute}-index"
22
- options = self.default_options
23
- options.merge!(key_conditions: key_conditions, index_name: index_name)
14
+ def where(opts={})
15
+ limit = opts.delete(:limit)
16
+ exclusive_start_key = opts.delete(:exclusive_start_key)
24
17
 
25
- response = self.client.query(options)
26
- DynamoRecord::Collection.new(response, self)
27
- end
28
-
29
- def find_by_hash_and_range(hash_key, range_key=nil)
30
18
  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' }
19
+ opts.each do |key, value|
20
+ key_conditions[key] = { attribute_value_list: [value],
21
+ comparison_operator: 'EQ' }
36
22
  end
37
-
23
+
38
24
  options = self.default_options
39
25
  options.merge!(key_conditions: key_conditions)
26
+ options.merge!(limit: limit) if limit
27
+ options.merge!(exclusive_start_key: exclusive_start_key) if exclusive_start_key
40
28
 
41
29
  response = self.client.query(options)
42
30
  DynamoRecord::Collection.new(response, self)
@@ -1,3 +1,3 @@
1
1
  module DynamoRecord
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
@@ -43,23 +43,33 @@ RSpec.describe DynamoRecord::Query, :vcr do
43
43
 
44
44
  describe 'querying' do
45
45
 
46
- describe '#find_by_hash_and_range' do
46
+ describe '#where' do
47
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)
48
+ result = PersonRange.where(id: '1', created_at: '2015-01-28T14:37:01+08:00')
49
+ expect(result.count).to eq(1)
50
50
  end
51
51
 
52
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)
53
+ result = PersonRange.where(id: '1')
54
+ expect(result.count).to eq(2)
55
55
  end
56
- end
57
56
 
58
- describe '#where' do
59
- it 'queries by condition' do
60
- people = Person.where(name: 'Person 2')
61
- expect(people.map(&:name)).to eq(['Person 2'])
57
+ it 'returns records by limit' do
58
+ result = PersonRange.where(id: '1', limit: 1)
59
+ expect(result.count).to eq(1)
60
+ expect(result.last_evaluated_key).to eq({'id' => '1', 'created_at' => '2015-01-28T14:37:01+08:00'})
62
61
  end
62
+
63
+ it 'returs records from a exclusive start key' do
64
+ result = PersonRange.where(id: '1', limit: 1, exclusive_start_key: { id: '1', created_at: '2015-01-28T14:37:01+08:00'})
65
+ expect(result.count).to eq(1)
66
+ expect(result.first.created_at).to eq('2015-01-29T14:36:59+08:00')
67
+ end
68
+
69
+ # it 'queries by index' do
70
+ # people = Person.where(name: 'Person 2')
71
+ # expect(people.map(&:name)).to eq(['Person 2'])
72
+ # end
63
73
  end
64
74
  end
65
75
  end
@@ -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
+ - 20150130T100706Z
20
+ X-Amz-Content-Sha256:
21
+ - cb65882116db16faf18fa6cfb02eb793e9952156441a23509c56b3dcc37abd33
22
+ Authorization:
23
+ - AWS4-HMAC-SHA256 Credential=AKIAJGUSFVPIJ4LHTPCQ/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=f5607d39d690a827090479181c8a2e5a750248cf153058a03b4a9ee1bac83d26
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
+ - G5A2V2VA4B1KG5RCJ2L64I9I67VV4KQNSO5AEMVJF66Q9ASUAAJG
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 10:07:05 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 10:07:07 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
+ - 20150130T102746Z
20
+ X-Amz-Content-Sha256:
21
+ - f04e6fb149222c33132f14b3dd507d21d3deae8d7d2458d4bfd9466dfc628bbb
22
+ Authorization:
23
+ - AWS4-HMAC-SHA256 Credential=AKIAJGUSFVPIJ4LHTPCQ/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=9dbda708e3aac989811b21e1c0a6b8069c3849f4094f06b9c35e5fff12446e17
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
+ - J514T624ES4EIPC5UT4CD53G83VV4KQNSO5AEMVJF66Q9ASUAAJG
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 10:27:46 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 10:27:48 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"}},"Limit":1}'
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
+ - 20150130T110726Z
20
+ X-Amz-Content-Sha256:
21
+ - b4af37d38eefd1f8a6ea35316c1143ed40ac770879fa9925828593c4f2455dca
22
+ Authorization:
23
+ - AWS4-HMAC-SHA256 Credential=AKIAJGUSFVPIJ4LHTPCQ/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=1f6a2dc7ca9e74c858ccff35aaf93c146d616c4467f2b923ce748259b591fc27
26
+ Content-Length:
27
+ - '123'
28
+ Accept:
29
+ - "*/*"
30
+ response:
31
+ status:
32
+ code: 200
33
+ message: OK
34
+ headers:
35
+ X-Amzn-Requestid:
36
+ - K44IKN35TKK5E60D741EOFP6A3VV4KQNSO5AEMVJF66Q9ASUAAJG
37
+ X-Amz-Crc32:
38
+ - '2443797734'
39
+ Content-Type:
40
+ - application/x-amz-json-1.0
41
+ Content-Length:
42
+ - '185'
43
+ Date:
44
+ - Fri, 30 Jan 2015 11:07:27 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"}}],"LastEvaluatedKey":{"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 11:07:28 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"}},"Limit":1}'
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
+ - 20150130T111049Z
20
+ X-Amz-Content-Sha256:
21
+ - b4af37d38eefd1f8a6ea35316c1143ed40ac770879fa9925828593c4f2455dca
22
+ Authorization:
23
+ - AWS4-HMAC-SHA256 Credential=AKIAJGUSFVPIJ4LHTPCQ/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=862d4ed0954b52d2c174e0791703cbbf51ac87571bc7adcbc9d409145579a618
26
+ Content-Length:
27
+ - '123'
28
+ Accept:
29
+ - "*/*"
30
+ response:
31
+ status:
32
+ code: 200
33
+ message: OK
34
+ headers:
35
+ X-Amzn-Requestid:
36
+ - EHME68LLV5620M22V46CER32DRVV4KQNSO5AEMVJF66Q9ASUAAJG
37
+ X-Amz-Crc32:
38
+ - '2443797734'
39
+ Content-Type:
40
+ - application/x-amz-json-1.0
41
+ Content-Length:
42
+ - '185'
43
+ Date:
44
+ - Fri, 30 Jan 2015 11:10:49 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"}}],"LastEvaluatedKey":{"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 11:10:50 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"}},"Limit":1,"ExclusiveStartKey":{"id":{"S":"1"},"created_at":{"S":"2015-01-28T14:37:01+08:00"}}}'
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
+ - 20150130T111050Z
20
+ X-Amz-Content-Sha256:
21
+ - 3deaf477f931d53e7bee2b2c523632b105e5987b027b9c2d989c8738d3d20711
22
+ Authorization:
23
+ - AWS4-HMAC-SHA256 Credential=AKIAJGUSFVPIJ4LHTPCQ/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=c32fc1ca3fd87c961d7456c90575939967e477955d996344ab1ac37c4e489492
26
+ Content-Length:
27
+ - '207'
28
+ Accept:
29
+ - "*/*"
30
+ response:
31
+ status:
32
+ code: 200
33
+ message: OK
34
+ headers:
35
+ X-Amzn-Requestid:
36
+ - V1P73GS8J7U1UM869OKHNVOF9JVV4KQNSO5AEMVJF66Q9ASUAAJG
37
+ X-Amz-Crc32:
38
+ - '542610492'
39
+ Content-Type:
40
+ - application/x-amz-json-1.0
41
+ Content-Length:
42
+ - '185'
43
+ Date:
44
+ - Fri, 30 Jan 2015 11:10:51 GMT
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"Count":1,"Items":[{"created_at":{"S":"2015-01-29T14:36:59+08:00"},"id":{"S":"1"}}],"LastEvaluatedKey":{"created_at":{"S":"2015-01-29T14:36:59+08:00"},"id":{"S":"1"}},"ScannedCount":1}'
48
+ http_version:
49
+ recorded_at: Fri, 30 Jan 2015 11:10:52 GMT
50
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamo_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nguyen Vu Nguyen
@@ -163,7 +163,11 @@ files:
163
163
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/_query/queries_by_condition.yml
164
164
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_a_record_by_hash_key_and_range_key.yml
165
165
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_all_records_by_hash_key.yml
166
- - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/queries_by_condition.yml
166
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_a_record_by_hash_key_and_range_key.yml
167
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_all_records_by_hash_key.yml
168
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_by_limit.yml
169
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_records_by_limit.yml
170
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returs_records_from_a_exclusive_start_key.yml
167
171
  - spec/spec_helper.rb
168
172
  homepage: https://github.com/yetanothernguyen/dynamo_record
169
173
  licenses:
@@ -223,5 +227,9 @@ test_files:
223
227
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/_query/queries_by_condition.yml
224
228
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_a_record_by_hash_key_and_range_key.yml
225
229
  - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_find_by_hash_and_range/returns_all_records_by_hash_key.yml
226
- - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/queries_by_condition.yml
230
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_a_record_by_hash_key_and_range_key.yml
231
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_all_records_by_hash_key.yml
232
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_by_limit.yml
233
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returns_records_by_limit.yml
234
+ - spec/fixtures/vcr_cassettes/DynamoRecord_Query/querying/_where/returs_records_from_a_exclusive_start_key.yml
227
235
  - spec/spec_helper.rb
@@ -1,53 +0,0 @@
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":"people","KeyConditions":{"name":{"AttributeValueList":[{"S":"Person
9
- 2"}],"ComparisonOperator":"EQ"}},"IndexName":"name-index"}'
10
- headers:
11
- Content-Type:
12
- - application/x-amz-json-1.0
13
- Accept-Encoding:
14
- - ''
15
- User-Agent:
16
- - aws-sdk-ruby2/2.0.17 ruby/2.1.2 x86_64-darwin14.0
17
- X-Amz-Target:
18
- - DynamoDB_20120810.Query
19
- X-Amz-Date:
20
- - 20141231T085539Z
21
- Host:
22
- - dynamodb.us-east-1.amazonaws.com
23
- X-Amz-Content-Sha256:
24
- - ff6d076e5a2413b9a7418bff017d084acec8dd4d4c60130cdec7a10d31bbb509
25
- Authorization:
26
- - AWS4-HMAC-SHA256 Credential=key/20141231/us-east-1/dynamodb/aws4_request,
27
- SignedHeaders=content-type;host;user-agent;x-amz-content-sha256;x-amz-date;x-amz-target,
28
- Signature=d5f28292bfc3a2fd70c69cbb4db87b15087f92b1b4b4f656036db8005c4a3854
29
- Content-Length:
30
- - '140'
31
- Accept:
32
- - "*/*"
33
- response:
34
- status:
35
- code: 200
36
- message: OK
37
- headers:
38
- X-Amzn-Requestid:
39
- - KSCIU2Q8KNE6JDTJO67BT0FAVFVV4KQNSO5AEMVJF66Q9ASUAAJG
40
- X-Amz-Crc32:
41
- - '2069429624'
42
- Content-Type:
43
- - application/x-amz-json-1.0
44
- Content-Length:
45
- - '114'
46
- Date:
47
- - Wed, 31 Dec 2014 08:55:40 GMT
48
- body:
49
- encoding: UTF-8
50
- string: '{"Count":1,"Items":[{"name":{"S":"Person 2"},"id":{"S":"611b5bc7-849f-4e0c-b969-5b53b6f2d0e2"}}],"ScannedCount":1}'
51
- http_version:
52
- recorded_at: Wed, 31 Dec 2014 08:55:41 GMT
53
- recorded_with: VCR 2.9.3