dynamodb_record 0.2.0 → 0.2.2

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: e0019712191d0f7ba069ba581bd04a59a5c9dd985d34bc5f7cb2865f08820ac4
4
+ data.tar.gz: 02ebcbed904cfeca08deb41a315ea9a018068f1be9747a8e884b289e782a132e
5
5
  SHA512:
6
- metadata.gz: 71c72c3eac3ce2212c19894745d03087c0466c1fa2cfc7bc29bf23d123f7204f7cc7eae96d37c199180786ea31fe5248e2fbceba294ff57acbd8d53d44aa8ac3
7
- data.tar.gz: '082aa5bb291c03ad4963a101e32efa070c10b403e1d5ca55f172ab7c60a26a7ceb5556d527e35e2bea04bf412762244accddc801d082903e08808dcda7f294a2'
6
+ metadata.gz: f6ea7a0acbdf7f5eaa2ebecd8aef15613fafe0337af8ab67d31b648572ed51cf0b08fd24b06dc137895ebd6f2d6e6789cf942b961e708d5e33c67f32a9bbb27e
7
+ data.tar.gz: 8cbd27b3dc8a12546aadeeabff96d94a4b8e3a562dbef7f2d980acdf7dea7f73ef863a17c62e4b5e662e7661383f5da59d54dadaad556881d3fcdfcae744e8a5
@@ -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
@@ -59,6 +59,12 @@ module DynamodbRecord
59
59
  else
60
60
  DateTime.parse(value)
61
61
  end
62
+ when :array
63
+ if value.is_a?(Array)
64
+ value
65
+ else
66
+ raise ArgumentError, 'Array column'
67
+ end
62
68
  else
63
69
  raise ArgumentError, "Unknown type #{options[:type]}"
64
70
  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.2'
5
5
  end
@@ -42,12 +42,14 @@ RSpec.describe DynamodbRecord::Fields do
42
42
  field :big_decimal_field, :big_decimal
43
43
  field :datetime_field, :datetime
44
44
  field :boolean_field, :boolean
45
+ field :array_field, :array
45
46
  end
46
47
 
47
48
  expect(Record.new(integer_field: '1').integer_field).to be_a(Integer)
48
49
  expect(Record.new(big_decimal_field: '1').big_decimal_field).to be_a(BigDecimal)
49
50
  expect(Record.new(datetime_field: '2014-12-25T04:08:25Z').datetime_field).to eq(DateTime.parse('2014-12-25T04:08:25Z'))
50
51
  expect(Record.new(boolean_field: 'true').boolean_field).to be_truthy
52
+ expect(Record.new(array_field: %w[admin assistant]).array_field).to be_truthy
51
53
  end
52
54
 
53
55
  it 'coearce field to its data type when calling writer' do
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DynamodbRecord::Query, :vcr do
4
+ describe '#all' do
5
+ it 'find all records' do
6
+ user = User.all
7
+ expect(user.count).to eq(1)
8
+ expect(user.map(&:id)).to eq(['hguzman20@gmail.com'])
9
+ end
10
+ end
11
+ describe 'querying' do
12
+ describe '#where' do
13
+ it 'returns records where user balance = 0' do
14
+ result = User.where(balance: 0, limit: 1)
15
+ expect(result.count).to eq(1)
16
+ end
17
+
18
+ it 'returns records by limit' do
19
+ result = User.where(balance: 0, limit: 1)
20
+ expect(result.count).to eq(1)
21
+ expect(result.last_evaluated_key).to eq('eyJpZCI6ImhndXptYW4yMEBnbWFpbC5jb20ifQ==')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users"}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.Scan
16
+ User-Agent:
17
+ - 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
18
+ md/3.2.3 cfg/retry-mode#legacy
19
+ Host:
20
+ - localhost:8000
21
+ X-Amz-Date:
22
+ - 20240502T233108Z
23
+ X-Amz-Content-Sha256:
24
+ - 4beda0215c9ab83d1b5bba1ba2744d5a230ca7b206aad0ffee3f6bdabcff87c5
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=key/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=3c16286960a3799524892b4f88f09834f964adeed8923815f8a6e82884e3ee47
29
+ Content-Length:
30
+ - '21'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 23:31:08 GMT
40
+ X-Amzn-Requestid:
41
+ - 4379a646-85d4-4f6b-ba53-d7edfabd1ec2
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ X-Amz-Crc32:
45
+ - '2922398473'
46
+ Content-Length:
47
+ - '111'
48
+ Server:
49
+ - Jetty(11.0.17)
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"Items":[{"balance":{"N":"0"},"token":{"N":"0"},"id":{"S":"hguzman20@gmail.com"}}],"Count":1,"ScannedCount":1}'
53
+ recorded_at: Thu, 02 May 2024 23:31:08 GMT
54
+ 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
+ - 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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henry Guzman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-05-02 00:00:00.000000000 Z
12
+ date: 2024-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -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,9 @@ 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/_all/find_all_records.yml
201
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_by_limit.yml
202
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_where_user_balance_0.yml
199
203
  - spec/spec_helper.rb
200
204
  homepage: https://github.com/CarsOk/dynamodb-record
201
205
  licenses:
@@ -228,6 +232,7 @@ test_files:
228
232
  - spec/dynamodb_record/fields_spec.rb
229
233
  - spec/dynamodb_record/finders_spec.rb
230
234
  - spec/dynamodb_record/persistence_spec.rb
235
+ - spec/dynamodb_record/query_spec.rb
231
236
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Document/initializes_from_database.yml
232
237
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml
233
238
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml
@@ -236,4 +241,7 @@ test_files:
236
241
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/does_not_overwrite_existing_record.yml
237
242
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/saves_record.yml
238
243
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/updates_record.yml
244
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/_all/find_all_records.yml
245
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_by_limit.yml
246
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Query/querying/_where/returns_records_where_user_balance_0.yml
239
247
  - spec/spec_helper.rb