dynamodb_record 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49693eaf2b663b1061fd4c1bb498fa8c1bc6f2d49ec3a02b5a85fe7fd5cd3161
4
- data.tar.gz: a52d2fdfddbe64f06f50d60e4076c57eae6093b6615f88743af1d557bb73b8eb
3
+ metadata.gz: b546031e49e8c58f4558997fc379165a340b30cf0c0a48623d0131d0c31a856e
4
+ data.tar.gz: 640ec20a1140aee774680c48dd09cdde5479b7a12ee50dc75b21fc4c42f6991d
5
5
  SHA512:
6
- metadata.gz: 71c72c3eac3ce2212c19894745d03087c0466c1fa2cfc7bc29bf23d123f7204f7cc7eae96d37c199180786ea31fe5248e2fbceba294ff57acbd8d53d44aa8ac3
7
- data.tar.gz: '082aa5bb291c03ad4963a101e32efa070c10b403e1d5ca55f172ab7c60a26a7ceb5556d527e35e2bea04bf412762244accddc801d082903e08808dcda7f294a2'
6
+ metadata.gz: df2da8d859c9dc61321ba43030af5730b468a0bd96005afad9f6cafc7300ee2d0e0f5245eeb046f6240e5cb1406d55c4969990fc2a967d9ecc74f33709798732
7
+ data.tar.gz: 2809ab51cd5868a233da409f3041d5cab6a285ffbe1ae4c74c39910a16aed45cd0a961d402cdce22982e64cf666634a496d9dbd1574b5120a7c9fbb2042d1e73
@@ -9,7 +9,7 @@ module DynamodbRecord
9
9
  def initialize(pager, klass, options = {})
10
10
  @klass = klass
11
11
  @table_name = options[:table_name]
12
- @foreign_key = options[:expression_attribute_values].transform_keys { |k| k.delete_prefix(':').to_sym }
12
+ @foreign_key = options[:expression_attribute_values].transform_keys { |k| k.delete_prefix(':').to_sym } rescue nil
13
13
  @items = pager.items.map { |item| klass.send(:from_database, item) }
14
14
  @last_evaluated_key = pager.last_evaluated_key
15
15
  end
@@ -54,7 +54,7 @@ module DynamodbRecord
54
54
  indexes << key if value[:options][:index]
55
55
  end
56
56
 
57
- global_secondary_indexes = []
57
+ global_secoglobal_secondary_indexesndary_indexes = []
58
58
  indexes.each do |index|
59
59
  index_definition = {}
60
60
  index_definition[:index_name] = "#{index}_index"
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
 
3
2
  module DynamodbRecord
4
3
  # Query Module
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamodbRecord
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DynamodbRecord::Query, :vcr do
4
+ describe 'querying' do
5
+ describe '#where' do
6
+ it 'returns records where user balance = 0' do
7
+ result = User.where(balance: 0, limit: 1)
8
+ expect(result.count).to eq(1)
9
+ end
10
+
11
+ it 'returns records by limit' do
12
+ result = User.where(balance: 0, limit: 1)
13
+ expect(result.count).to eq(1)
14
+ expect(result.last_evaluated_key).to eq('eyJpZCI6ImhndXptYW4yMEBnbWFpbC5jb20ifQ==')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users","Limit":1,"ExpressionAttributeNames":{"#balance":"balance"},"ExpressionAttributeValues":{":balance":{"N":"0"}},"FilterExpression":"#balance
9
+ = :balance"}'
10
+ headers:
11
+ Accept-Encoding:
12
+ - ''
13
+ Content-Type:
14
+ - application/x-amz-json-1.0
15
+ X-Amz-Target:
16
+ - DynamoDB_20120810.Scan
17
+ User-Agent:
18
+ - aws-sdk-ruby3/3.191.3 ua/2.0 api/dynamodb#1.105.0 os/macos#20 md/x86_64 lang/ruby#3.2.3
19
+ md/3.2.3 cfg/retry-mode#legacy
20
+ Host:
21
+ - localhost:8000
22
+ X-Amz-Date:
23
+ - 20240502T230053Z
24
+ X-Amz-Content-Sha256:
25
+ - 3251e11bdd19fdce2e7d146498b881bbbc65f57b12aa6ad4cb1443d5cda934f1
26
+ Authorization:
27
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
28
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
29
+ Signature=d4e6a9939d2f6d6a3de5d87294a73e1d5a18160524ef4a01c4c562777a21bc23
30
+ Content-Length:
31
+ - '173'
32
+ Accept:
33
+ - "*/*"
34
+ response:
35
+ status:
36
+ code: 200
37
+ message: OK
38
+ headers:
39
+ Date:
40
+ - Thu, 02 May 2024 23:00:53 GMT
41
+ X-Amzn-Requestid:
42
+ - f4c8a18f-9421-41e1-82e0-084fda5e62d9
43
+ Content-Type:
44
+ - application/x-amz-json-1.0
45
+ X-Amz-Crc32:
46
+ - '2270305145'
47
+ Content-Length:
48
+ - '165'
49
+ Server:
50
+ - Jetty(11.0.17)
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"Items":[{"balance":{"N":"0"},"token":{"N":"0"},"id":{"S":"hguzman20@gmail.com"}}],"Count":1,"ScannedCount":1,"LastEvaluatedKey":{"id":{"S":"hguzman20@gmail.com"}}}'
54
+ recorded_at: Thu, 02 May 2024 23:00:53 GMT
55
+ recorded_with: VCR 6.2.0
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users","Limit":1,"ExpressionAttributeNames":{"#balance":"balance"},"ExpressionAttributeValues":{":balance":{"N":"0"}},"FilterExpression":"#balance
9
+ = :balance"}'
10
+ headers:
11
+ Accept-Encoding:
12
+ - ''
13
+ Content-Type:
14
+ - application/x-amz-json-1.0
15
+ X-Amz-Target:
16
+ - DynamoDB_20120810.Scan
17
+ User-Agent:
18
+ - aws-sdk-ruby3/3.191.3 ua/2.0 api/dynamodb#1.105.0 os/macos#20 md/x86_64 lang/ruby#3.2.3
19
+ md/3.2.3 cfg/retry-mode#legacy
20
+ Host:
21
+ - localhost:8000
22
+ X-Amz-Date:
23
+ - 20240502T225836Z
24
+ X-Amz-Content-Sha256:
25
+ - 3251e11bdd19fdce2e7d146498b881bbbc65f57b12aa6ad4cb1443d5cda934f1
26
+ Authorization:
27
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
28
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
29
+ Signature=43c96e9e8cc7e2db0b5aca42322fa559c7f2766689a3ea1b527256ea5a7dbee3
30
+ Content-Length:
31
+ - '173'
32
+ Accept:
33
+ - "*/*"
34
+ response:
35
+ status:
36
+ code: 200
37
+ message: OK
38
+ headers:
39
+ Date:
40
+ - Thu, 02 May 2024 22:58:36 GMT
41
+ X-Amzn-Requestid:
42
+ - fc0e4805-bf6c-4190-9f20-eb06f8c72555
43
+ Content-Type:
44
+ - application/x-amz-json-1.0
45
+ X-Amz-Crc32:
46
+ - '2270305145'
47
+ Content-Length:
48
+ - '165'
49
+ Server:
50
+ - Jetty(11.0.17)
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"Items":[{"balance":{"N":"0"},"token":{"N":"0"},"id":{"S":"hguzman20@gmail.com"}}],"Count":1,"ScannedCount":1,"LastEvaluatedKey":{"id":{"S":"hguzman20@gmail.com"}}}'
54
+ recorded_at: Thu, 02 May 2024 22:58:36 GMT
55
+ recorded_with: VCR 6.2.0
data/spec/spec_helper.rb CHANGED
@@ -11,10 +11,13 @@ VCR.configure do |c|
11
11
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
12
12
  c.hook_into :webmock
13
13
  c.configure_rspec_metadata!
14
- c.default_cassette_options = { match_requests_on: %i[method uri body] }
14
+ c.default_cassette_options = { match_requests_on: %i[method uri] }
15
+ # c.default_cassette_options = { match_requests_on: %i[method uri body] }
15
16
  end
16
17
 
17
18
  DynamodbRecord.configure do |config|
18
19
  config.namespace = nil
19
20
  config.endpoint = 'http://localhost:8000'
21
+ config.access_key_id = ENV['DYNAMODB_KEY'] || 'key'
22
+ config.secret_access_key = ENV['DYNAMODB_SECRET'] || 'secret'
20
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Guzman
@@ -188,6 +188,7 @@ files:
188
188
  - spec/dynamodb_record/fields_spec.rb
189
189
  - spec/dynamodb_record/finders_spec.rb
190
190
  - spec/dynamodb_record/persistence_spec.rb
191
+ - spec/dynamodb_record/query_spec.rb
191
192
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Document/initializes_from_database.yml
192
193
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml
193
194
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml
@@ -196,6 +197,8 @@ files:
196
197
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/does_not_overwrite_existing_record.yml
197
198
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/saves_record.yml
198
199
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/updates_record.yml
200
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_by_limit.yml
201
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_where_user_balance_0.yml
199
202
  - spec/spec_helper.rb
200
203
  homepage: https://github.com/CarsOk/dynamodb-record
201
204
  licenses:
@@ -228,6 +231,7 @@ test_files:
228
231
  - spec/dynamodb_record/fields_spec.rb
229
232
  - spec/dynamodb_record/finders_spec.rb
230
233
  - spec/dynamodb_record/persistence_spec.rb
234
+ - spec/dynamodb_record/query_spec.rb
231
235
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Document/initializes_from_database.yml
232
236
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml
233
237
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml
@@ -236,4 +240,6 @@ test_files:
236
240
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/does_not_overwrite_existing_record.yml
237
241
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/saves_record.yml
238
242
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/updates_record.yml
243
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_by_limit.yml
244
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_where_user_balance_0.yml
239
245
  - spec/spec_helper.rb