dynamodb_record 0.0.2 → 0.2.0

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: 390ba8516fb8b5a58b440693b38162fc36139bb5e20f017b40569a0dc7033d16
4
- data.tar.gz: d849dfa255097beb3b8872a05bf896e3c1bd2f630461b1db700306c09ac1a365
3
+ metadata.gz: 49693eaf2b663b1061fd4c1bb498fa8c1bc6f2d49ec3a02b5a85fe7fd5cd3161
4
+ data.tar.gz: a52d2fdfddbe64f06f50d60e4076c57eae6093b6615f88743af1d557bb73b8eb
5
5
  SHA512:
6
- metadata.gz: d53e86c92d9e94eb5999e8ba5b781903b57876b6727aa33dc513f87c0b628cbd1a4ab47b55ecd67b18da9e60b236df4f1af79a65c36121875a6e4c5d07938142
7
- data.tar.gz: de1b46d33ae75d0450f82e9b8c30549f0bfc884ebe107c235390e84895d3a24b1aadde5e466a671b8ad8454c0574fd818168dc47dae6ef0d1d36e5dd75d81389
6
+ metadata.gz: 71c72c3eac3ce2212c19894745d03087c0466c1fa2cfc7bc29bf23d123f7204f7cc7eae96d37c199180786ea31fe5248e2fbceba294ff57acbd8d53d44aa8ac3
7
+ data.tar.gz: '082aa5bb291c03ad4963a101e32efa070c10b403e1d5ca55f172ab7c60a26a7ceb5556d527e35e2bea04bf412762244accddc801d082903e08808dcda7f294a2'
data/README.md CHANGED
@@ -7,7 +7,7 @@ A simple DynamoDB ORM container on aws-sdk v3 forked from https://github.com/yet
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'dynamo_record'
10
+ gem 'dynamodb_record'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -16,7 +16,7 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install dynamo_record
19
+ $ gem install dynamodb_record
20
20
 
21
21
  ## Usage
22
22
 
@@ -71,7 +71,10 @@ users = User.where(first_name: 'John', limit: 5)
71
71
 
72
72
  user = User.find('f9b351b0-d06d-4fff-b8d4-8af162e2b8ba')
73
73
  ```
74
-
74
+ #### With error
75
+ ```ruby
76
+ User.find!('f9b351b0-d06d-4fff-b8d4-8af162e2b8ba')
77
+ ```
75
78
 
76
79
  ## Contributing
77
80
 
@@ -5,12 +5,14 @@ module DynamodbRecord
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- class_attribute :attributes, :hash_key, instance_writer: true
8
+ class_attribute :attributes, instance_writer: true
9
9
  self.attributes = {}
10
- self.hash_key = nil
10
+ # self.hash_key = nil
11
11
 
12
12
  # default hash key
13
13
  field :id, :string
14
+ field :created_at, :datetime
15
+ field :updated_at, :datetime
14
16
  end
15
17
 
16
18
  class_methods do
@@ -19,7 +21,8 @@ module DynamodbRecord
19
21
  # Add attributes
20
22
  attributes.merge!(name => { type:, options: opts })
21
23
 
22
- self.hash_key = name if opts[:hash_key]
24
+ # self.hash_key = name if opts[:hash_key]
25
+ # self.range_key = name if opts[:range_key]
23
26
 
24
27
  # Generate methods to field
25
28
  define_method("#{named}=") { |value| write_attribute(named, value) }
@@ -75,28 +78,21 @@ module DynamodbRecord
75
78
  def unload(attrs)
76
79
  {}.tap do |hash|
77
80
  attrs.each do |key, value|
78
- if attributes[key.to_sym][:options][:hash_key]
79
- # puts "KEY #{key} | #{dump_field(value, self.attributes[key.to_sym])}"
80
- hash[:pk] = dump_field(value, attributes[key.to_sym])
81
- end
81
+ # if attributes[key.to_sym][:options][:hash_key]
82
+ # hash[:pk] = dump_field(value, attributes[key.to_sym])
83
+ # end
82
84
 
83
- # puts "KEY #{key}|#{value}|#{self.attributes[key.to_sym]}"
84
85
  hash[key] = dump_field(value, attributes[key.to_sym])
85
- # puts "HASH: #{hash}"
86
86
  end
87
87
  end
88
88
  end
89
89
 
90
90
  def hash_key
91
- :id # default hash key
91
+ @hash_key = attributes.select { |_k,v| v[:options][:hash_key] }.keys.first || :id
92
92
  end
93
93
 
94
94
  def range_key
95
- @range_key ||= begin
96
- attributes.select { |_k, v| v[:options][:range_key] }.keys.first
97
- rescue StandardError
98
- nil
99
- end
95
+ @range_key ||= attributes.select { |_k,v| v[:options][:range_key] }.keys.first rescue nil
100
96
  end
101
97
 
102
98
  def secondary_indexes
@@ -6,14 +6,21 @@ module DynamodbRecord
6
6
 
7
7
  class_methods do
8
8
  def find(id, range_key = nil)
9
- key = { 'id' => id }
9
+ find!(id, range_key)
10
+ rescue StandardError
11
+ nil
12
+ end
10
13
 
14
+ def find!(id, range_key = nil)
15
+ key = {}
16
+ key[hash_key] = id
11
17
  key[self.range_key] = range_key if self.range_key
18
+
12
19
  response = client.get_item(
13
20
  table_name:,
14
21
  key:
15
22
  )
16
- response.item ? from_database(response.item) : nil
23
+ response.item ? from_database(response.item) : raise('Record Not Found')
17
24
  end
18
25
  end
19
26
  end
@@ -108,19 +108,31 @@ module DynamodbRecord
108
108
  options = self.class.default_options
109
109
 
110
110
  self.id = SecureRandom.uuid if id.nil?
111
+ time = Time.now
112
+ self.created_at = time if created_at.nil?
113
+ self.updated_at = time
111
114
 
112
115
  if @new_record # New item. Don't overwrite if id exists
113
116
  options.merge!(condition_expression: 'id <> :s', expression_attribute_values: { ':s' => id })
114
117
  end
115
118
 
116
119
  options.merge!(item: self.class.unload(attributes))
120
+ # puts options
117
121
  self.class.client.put_item(options)
118
122
  @new_record = false
119
123
  end
120
124
 
121
125
  def destroy
122
126
  options = self.class.default_options
123
- key = { 'pk' => pk, 'sk' => sk }
127
+ hash_key = self.class.hash_key
128
+ range_key = self.class.range_key
129
+ key = {}
130
+ key[hash_key] = self.class.dump_field(self.read_attribute(hash_key), self.class.attributes[hash_key])
131
+
132
+ if range_key.present?
133
+ key[range_key] = self.class.dump_field(self.read_attribute(range_key), self.class.attributes[range_key])
134
+ end
135
+
124
136
  self.class.client.delete_item(options.merge(key:))
125
137
  end
126
138
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamodbRecord
4
- VERSION = '0.0.2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Authorization
4
+ include DynamodbRecord::Document
5
+
6
+ field :user_id, :string, hash_key: true
7
+ field :service_id, :string, range_key: true
8
+
9
+ end
@@ -17,9 +17,13 @@ RSpec.describe DynamodbRecord::Fields do
17
17
  end
18
18
  expect(Employee.attributes).to eq({ id: { type: :string, options: {} },
19
19
  first_name: { type: :string, options: {} },
20
- last_name: { type: :string, options: {} } })
20
+ last_name: { type: :string, options: {} },
21
+ created_at: { type: :datetime, options: {} },
22
+ updated_at: { type: :datetime, options: {} }
23
+ })
21
24
  end
22
25
 
26
+
23
27
  it 'accepts default value' do
24
28
  class City
25
29
  include DynamodbRecord::Document
@@ -4,18 +4,17 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe DynamodbRecord::Fields, :vcr do
6
6
  describe '#find' do
7
- # it 'finds record' do
8
- # user = User.find('hguzman10@gmail.com')
9
- # p user
10
- # expect(user.id).to eq('hguzman10@gmail.com')
11
- # expect(user.balance).to eq(0)
12
- # end
13
- #
14
- # context 'when record doesn\'t exists' do
15
- # it 'returns empty object' do
16
- # user = User.find('not here')
17
- # expect(user).to be_nil
18
- # end
19
- # end
7
+ it 'finds record' do
8
+ # user = User.find('hguzman10@gmail.com')
9
+ # expect(user.id).to eq('hguzman10@gmail.com')
10
+ # expect(user.balance).to eq(0)
11
+ end
12
+
13
+ context 'when record doesn\'t exists' do
14
+ # it 'returns empty object' do
15
+ # user = User.find('not here')
16
+ # expect(user).to be_nil
17
+ # end
18
+ end
20
19
  end
21
20
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DynamodbRecord::Persistence, :vcr do
4
+
5
+ it 'saves record' do
6
+ user = User.new(id: 'hguzman10@gmail.com')
7
+ user.save
8
+ expect(user.new_record).to be_falsy
9
+ expect(user.id).to eq('hguzman10@gmail.com')
10
+ end
11
+
12
+ it 'does not overwrite existing record' do
13
+ user = User.new(id: 'hguzman10@gmail.com', balance: 100)
14
+ expect(user.save).to be_falsy
15
+
16
+ user = User.find('hguzman10@gmail.com')
17
+ expect(user.balance).to_not eq(100)
18
+ end
19
+
20
+ it 'updates record' do
21
+ user = User.find('hguzman10@gmail.com')
22
+ user.balance = 60
23
+ user.save
24
+ user = User.find('hguzman10@gmail.com')
25
+ expect(user.balance).to eq(60)
26
+ end
27
+
28
+ describe '#destroy' do
29
+ context 'when no range key' do
30
+ it 'destroys record' do
31
+ user = User.find('hguzman10@gmail.com')
32
+ user.destroy
33
+ user = User.find('hguzman10@gmail.com')
34
+ expect(user).to be_nil
35
+ end
36
+ end
37
+
38
+ context 'when there is range key' do
39
+ it 'destroys record' do
40
+ authorization = Authorization.find!('hguzman10@gmail.com', '1')
41
+ authorization.destroy
42
+ authorization = Authorization.find('hguzman10@gmail.com', '1')
43
+ expect(authorization).to be_nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -19,13 +19,13 @@ http_interactions:
19
19
  Host:
20
20
  - localhost:8000
21
21
  X-Amz-Date:
22
- - 20240419T150314Z
22
+ - 20240426T004444Z
23
23
  X-Amz-Content-Sha256:
24
24
  - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
25
25
  Authorization:
26
- - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240419/us-east-1/dynamodb/aws4_request,
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240426/us-east-1/dynamodb/aws4_request,
27
27
  SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
- Signature=eabad8cbbf72dd69908f08a4144d979c1287ad246a253639c311a2ddda0ae2df
28
+ Signature=7ad9fd348878ca27a2ea9c93bd4ca02a6cefe8a455429d1f7d4931ff8004825e
29
29
  Content-Length:
30
30
  - '62'
31
31
  Accept:
@@ -36,9 +36,9 @@ http_interactions:
36
36
  message: OK
37
37
  headers:
38
38
  Date:
39
- - Fri, 19 Apr 2024 15:03:14 GMT
39
+ - Fri, 26 Apr 2024 00:44:44 GMT
40
40
  X-Amzn-Requestid:
41
- - 8dff3212-b275-4948-a0ff-197f620c2344
41
+ - 487bfb5e-a7fc-4bfd-9763-c61930591f5c
42
42
  Content-Type:
43
43
  - application/x-amz-json-1.0
44
44
  X-Amz-Crc32:
@@ -50,5 +50,5 @@ http_interactions:
50
50
  body:
51
51
  encoding: UTF-8
52
52
  string: '{"Item":{"balance":{"N":"0"},"id":{"S":"hguzman10@gmail.com"}}}'
53
- recorded_at: Fri, 19 Apr 2024 15:03:14 GMT
53
+ recorded_at: Fri, 26 Apr 2024 00:44:44 GMT
54
54
  recorded_with: VCR 6.2.0
@@ -19,13 +19,13 @@ http_interactions:
19
19
  Host:
20
20
  - localhost:8000
21
21
  X-Amz-Date:
22
- - 20240419T150314Z
22
+ - 20240426T004553Z
23
23
  X-Amz-Content-Sha256:
24
24
  - acbe242b07a1de9c8a8ac78119a8da7e4bf1d57c7d59ed18930d06ad600c9d6c
25
25
  Authorization:
26
- - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240419/us-east-1/dynamodb/aws4_request,
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240426/us-east-1/dynamodb/aws4_request,
27
27
  SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
- Signature=47085d1e327831fd245c6c4e369ab311a42ec360f91eb745820dec01bafc46d5
28
+ Signature=44e65913fed63c074acdcbfc2abde8a46e8e3d838e429f74386763ac63f32a00
29
29
  Content-Length:
30
30
  - '51'
31
31
  Accept:
@@ -36,9 +36,9 @@ http_interactions:
36
36
  message: OK
37
37
  headers:
38
38
  Date:
39
- - Fri, 19 Apr 2024 15:03:14 GMT
39
+ - Fri, 26 Apr 2024 00:45:53 GMT
40
40
  X-Amzn-Requestid:
41
- - cbb6dfa5-b168-48ab-a3d6-64eca11dbc6e
41
+ - '091b1c6c-4b29-4901-9748-c865bae5affb'
42
42
  Content-Type:
43
43
  - application/x-amz-json-1.0
44
44
  X-Amz-Crc32:
@@ -50,5 +50,5 @@ http_interactions:
50
50
  body:
51
51
  encoding: UTF-8
52
52
  string: "{}"
53
- recorded_at: Fri, 19 Apr 2024 15:03:14 GMT
53
+ recorded_at: Fri, 26 Apr 2024 00:45:53 GMT
54
54
  recorded_with: VCR 6.2.0
@@ -0,0 +1,156 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.GetItem
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
+ - 20240502T003644Z
23
+ X-Amz-Content-Sha256:
24
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=94cc004156fe51a634d7bc47199d168f53887124cadf4eaf91af8970cd7e0751
29
+ Content-Length:
30
+ - '62'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 00:36:44 GMT
40
+ X-Amzn-Requestid:
41
+ - 7bae8e3b-f05f-4711-809b-13029004a792
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ X-Amz-Crc32:
45
+ - '3547979423'
46
+ Content-Length:
47
+ - '158'
48
+ Server:
49
+ - Jetty(11.0.17)
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"Item":{"created_at":{"S":"2024-05-01T19:36:43-05:00"},"id":{"S":"hguzman10@gmail.com"},"balance":{"N":"60"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
53
+ recorded_at: Thu, 02 May 2024 00:36:44 GMT
54
+ - request:
55
+ method: post
56
+ uri: http://localhost:8000/
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
60
+ headers:
61
+ Accept-Encoding:
62
+ - ''
63
+ Content-Type:
64
+ - application/x-amz-json-1.0
65
+ X-Amz-Target:
66
+ - DynamoDB_20120810.DeleteItem
67
+ User-Agent:
68
+ - 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
69
+ md/3.2.3 cfg/retry-mode#legacy
70
+ Host:
71
+ - localhost:8000
72
+ X-Amz-Date:
73
+ - 20240502T003644Z
74
+ X-Amz-Content-Sha256:
75
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
76
+ Authorization:
77
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
78
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
79
+ Signature=961736055c2544461f423b2aeebefa85e0c7c0f3e5cbf1f6a3734be3c29ad1c2
80
+ Content-Length:
81
+ - '62'
82
+ Accept:
83
+ - "*/*"
84
+ response:
85
+ status:
86
+ code: 200
87
+ message: OK
88
+ headers:
89
+ Date:
90
+ - Thu, 02 May 2024 00:36:44 GMT
91
+ X-Amzn-Requestid:
92
+ - d9042a14-8c30-46a1-9ae1-3f352dff03ab
93
+ Content-Type:
94
+ - application/x-amz-json-1.0
95
+ X-Amz-Crc32:
96
+ - '2745614147'
97
+ Content-Length:
98
+ - '2'
99
+ Server:
100
+ - Jetty(11.0.17)
101
+ body:
102
+ encoding: UTF-8
103
+ string: "{}"
104
+ recorded_at: Thu, 02 May 2024 00:36:44 GMT
105
+ - request:
106
+ method: post
107
+ uri: http://localhost:8000/
108
+ body:
109
+ encoding: UTF-8
110
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
111
+ headers:
112
+ Accept-Encoding:
113
+ - ''
114
+ Content-Type:
115
+ - application/x-amz-json-1.0
116
+ X-Amz-Target:
117
+ - DynamoDB_20120810.GetItem
118
+ User-Agent:
119
+ - 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
120
+ md/3.2.3 cfg/retry-mode#legacy
121
+ Host:
122
+ - localhost:8000
123
+ X-Amz-Date:
124
+ - 20240502T003644Z
125
+ X-Amz-Content-Sha256:
126
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
127
+ Authorization:
128
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
129
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
130
+ Signature=94cc004156fe51a634d7bc47199d168f53887124cadf4eaf91af8970cd7e0751
131
+ Content-Length:
132
+ - '62'
133
+ Accept:
134
+ - "*/*"
135
+ response:
136
+ status:
137
+ code: 200
138
+ message: OK
139
+ headers:
140
+ Date:
141
+ - Thu, 02 May 2024 00:36:44 GMT
142
+ X-Amzn-Requestid:
143
+ - d8e23373-1aee-4727-839e-fed721efdc77
144
+ Content-Type:
145
+ - application/x-amz-json-1.0
146
+ X-Amz-Crc32:
147
+ - '2745614147'
148
+ Content-Length:
149
+ - '2'
150
+ Server:
151
+ - Jetty(11.0.17)
152
+ body:
153
+ encoding: UTF-8
154
+ string: "{}"
155
+ recorded_at: Thu, 02 May 2024 00:36:44 GMT
156
+ recorded_with: VCR 6.2.0
@@ -0,0 +1,156 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"authorizations","Key":{"user_id":{"S":"hguzman10@gmail.com"},"service_id":{"S":"1"}}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.GetItem
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
+ - 20240502T001527Z
23
+ X-Amz-Content-Sha256:
24
+ - 904e20d3b7d573308942eb45e345aed8a0d28331d9087eb40a19412554c62258
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=a27d2463aed9f0c4f86c0db83f3d99d3e15b3482533e4d3c4430fda0de0e1312
29
+ Content-Length:
30
+ - '99'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 00:15:27 GMT
40
+ X-Amzn-Requestid:
41
+ - b0ad8800-588e-433b-b314-539bd7598d91
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ X-Amz-Crc32:
45
+ - '2017503589'
46
+ Content-Length:
47
+ - '71'
48
+ Server:
49
+ - Jetty(11.0.17)
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"Item":{"user_id":{"S":"hguzman10@gmail.com"},"service_id":{"S":"1"}}}'
53
+ recorded_at: Thu, 02 May 2024 00:15:27 GMT
54
+ - request:
55
+ method: post
56
+ uri: http://localhost:8000/
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"TableName":"authorizations","Key":{"user_id":{"S":"hguzman10@gmail.com"},"service_id":{"S":"1"}}}'
60
+ headers:
61
+ Accept-Encoding:
62
+ - ''
63
+ Content-Type:
64
+ - application/x-amz-json-1.0
65
+ X-Amz-Target:
66
+ - DynamoDB_20120810.DeleteItem
67
+ User-Agent:
68
+ - 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
69
+ md/3.2.3 cfg/retry-mode#legacy
70
+ Host:
71
+ - localhost:8000
72
+ X-Amz-Date:
73
+ - 20240502T001527Z
74
+ X-Amz-Content-Sha256:
75
+ - 904e20d3b7d573308942eb45e345aed8a0d28331d9087eb40a19412554c62258
76
+ Authorization:
77
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
78
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
79
+ Signature=8b44cb46b1680b538fe9455591b2a9cc8d28fd93ac35a154afed681e468130fd
80
+ Content-Length:
81
+ - '99'
82
+ Accept:
83
+ - "*/*"
84
+ response:
85
+ status:
86
+ code: 200
87
+ message: OK
88
+ headers:
89
+ Date:
90
+ - Thu, 02 May 2024 00:15:27 GMT
91
+ X-Amzn-Requestid:
92
+ - '016797fb-ab5f-4574-88f3-7e826cac42df'
93
+ Content-Type:
94
+ - application/x-amz-json-1.0
95
+ X-Amz-Crc32:
96
+ - '2745614147'
97
+ Content-Length:
98
+ - '2'
99
+ Server:
100
+ - Jetty(11.0.17)
101
+ body:
102
+ encoding: UTF-8
103
+ string: "{}"
104
+ recorded_at: Thu, 02 May 2024 00:15:27 GMT
105
+ - request:
106
+ method: post
107
+ uri: http://localhost:8000/
108
+ body:
109
+ encoding: UTF-8
110
+ string: '{"TableName":"authorizations","Key":{"user_id":{"S":"hguzman10@gmail.com"},"service_id":{"S":"1"}}}'
111
+ headers:
112
+ Accept-Encoding:
113
+ - ''
114
+ Content-Type:
115
+ - application/x-amz-json-1.0
116
+ X-Amz-Target:
117
+ - DynamoDB_20120810.GetItem
118
+ User-Agent:
119
+ - 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
120
+ md/3.2.3 cfg/retry-mode#legacy
121
+ Host:
122
+ - localhost:8000
123
+ X-Amz-Date:
124
+ - 20240502T001527Z
125
+ X-Amz-Content-Sha256:
126
+ - 904e20d3b7d573308942eb45e345aed8a0d28331d9087eb40a19412554c62258
127
+ Authorization:
128
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
129
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
130
+ Signature=a27d2463aed9f0c4f86c0db83f3d99d3e15b3482533e4d3c4430fda0de0e1312
131
+ Content-Length:
132
+ - '99'
133
+ Accept:
134
+ - "*/*"
135
+ response:
136
+ status:
137
+ code: 200
138
+ message: OK
139
+ headers:
140
+ Date:
141
+ - Thu, 02 May 2024 00:15:27 GMT
142
+ X-Amzn-Requestid:
143
+ - f7ad1c7f-8266-4da1-8355-7200d06d4f97
144
+ Content-Type:
145
+ - application/x-amz-json-1.0
146
+ X-Amz-Crc32:
147
+ - '2745614147'
148
+ Content-Length:
149
+ - '2'
150
+ Server:
151
+ - Jetty(11.0.17)
152
+ body:
153
+ encoding: UTF-8
154
+ string: "{}"
155
+ recorded_at: Thu, 02 May 2024 00:15:27 GMT
156
+ recorded_with: VCR 6.2.0
@@ -0,0 +1,104 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users","ConditionExpression":"id <> :s","ExpressionAttributeValues":{":s":{"S":"hguzman10@gmail.com"}},"Item":{"balance":{"N":"100"},"id":{"S":"hguzman10@gmail.com"},"created_at":{"S":"2024-05-01T19:36:43-05:00"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.PutItem
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
+ - 20240502T003643Z
23
+ X-Amz-Content-Sha256:
24
+ - 6ba894a3f3d7e47c03481928aa642e796e2e8b11c8f7a85324b66918fabe67fb
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=ecc9987a544fe53aa846cf53473b4438e6c7ca89b3db1d77cc163d28965c0d34
29
+ Content-Length:
30
+ - '275'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 400
36
+ message: Bad Request
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 00:36:43 GMT
40
+ X-Amzn-Requestid:
41
+ - abb2b185-4ffa-4b9e-b7b9-73a56fe18b8f
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ Content-Length:
45
+ - '120'
46
+ Server:
47
+ - Jetty(11.0.17)
48
+ body:
49
+ encoding: UTF-8
50
+ string: '{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","Message":"The
51
+ conditional request failed"}'
52
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
53
+ - request:
54
+ method: post
55
+ uri: http://localhost:8000/
56
+ body:
57
+ encoding: UTF-8
58
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
59
+ headers:
60
+ Accept-Encoding:
61
+ - ''
62
+ Content-Type:
63
+ - application/x-amz-json-1.0
64
+ X-Amz-Target:
65
+ - DynamoDB_20120810.GetItem
66
+ User-Agent:
67
+ - 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
68
+ md/3.2.3 cfg/retry-mode#legacy
69
+ Host:
70
+ - localhost:8000
71
+ X-Amz-Date:
72
+ - 20240502T003643Z
73
+ X-Amz-Content-Sha256:
74
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
75
+ Authorization:
76
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
77
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
78
+ Signature=e61f5c53269131bf5f985bfbe1385615456dcedad7ae5fce0fe1ce0a4e854705
79
+ Content-Length:
80
+ - '62'
81
+ Accept:
82
+ - "*/*"
83
+ response:
84
+ status:
85
+ code: 200
86
+ message: OK
87
+ headers:
88
+ Date:
89
+ - Thu, 02 May 2024 00:36:43 GMT
90
+ X-Amzn-Requestid:
91
+ - 05b8fc5c-d523-4191-bac0-d31621e3857c
92
+ Content-Type:
93
+ - application/x-amz-json-1.0
94
+ X-Amz-Crc32:
95
+ - '1030740054'
96
+ Content-Length:
97
+ - '157'
98
+ Server:
99
+ - Jetty(11.0.17)
100
+ body:
101
+ encoding: UTF-8
102
+ string: '{"Item":{"created_at":{"S":"2024-05-01T19:36:43-05:00"},"id":{"S":"hguzman10@gmail.com"},"balance":{"N":"0"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
103
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
104
+ recorded_with: VCR 6.2.0
@@ -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","ConditionExpression":"id <> :s","ExpressionAttributeValues":{":s":{"S":"hguzman10@gmail.com"}},"Item":{"balance":{"N":"0"},"id":{"S":"hguzman10@gmail.com"},"created_at":{"S":"2024-05-01T19:36:43-05:00"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.PutItem
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
+ - 20240502T003643Z
23
+ X-Amz-Content-Sha256:
24
+ - a6814143d7653f7f2d9abb6d2cf7c7b12ba0b621092b359971c44569d1bc2778
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=28275abed7119af00065965863f46b56a8f8db07e4ac789d86411f1f2c44155c
29
+ Content-Length:
30
+ - '273'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 00:36:43 GMT
40
+ X-Amzn-Requestid:
41
+ - c07e3cbf-e2be-4eb3-afb6-dad85bcdbe3f
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ X-Amz-Crc32:
45
+ - '2745614147'
46
+ Content-Length:
47
+ - '2'
48
+ Server:
49
+ - Jetty(11.0.17)
50
+ body:
51
+ encoding: UTF-8
52
+ string: "{}"
53
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
54
+ recorded_with: VCR 6.2.0
@@ -0,0 +1,156 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:8000/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
9
+ headers:
10
+ Accept-Encoding:
11
+ - ''
12
+ Content-Type:
13
+ - application/x-amz-json-1.0
14
+ X-Amz-Target:
15
+ - DynamoDB_20120810.GetItem
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
+ - 20240502T003643Z
23
+ X-Amz-Content-Sha256:
24
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
25
+ Authorization:
26
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
27
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
28
+ Signature=e61f5c53269131bf5f985bfbe1385615456dcedad7ae5fce0fe1ce0a4e854705
29
+ Content-Length:
30
+ - '62'
31
+ Accept:
32
+ - "*/*"
33
+ response:
34
+ status:
35
+ code: 200
36
+ message: OK
37
+ headers:
38
+ Date:
39
+ - Thu, 02 May 2024 00:36:43 GMT
40
+ X-Amzn-Requestid:
41
+ - ecb90d9f-4d44-400e-82f0-20214b690e4c
42
+ Content-Type:
43
+ - application/x-amz-json-1.0
44
+ X-Amz-Crc32:
45
+ - '1030740054'
46
+ Content-Length:
47
+ - '157'
48
+ Server:
49
+ - Jetty(11.0.17)
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"Item":{"created_at":{"S":"2024-05-01T19:36:43-05:00"},"id":{"S":"hguzman10@gmail.com"},"balance":{"N":"0"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
53
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
54
+ - request:
55
+ method: post
56
+ uri: http://localhost:8000/
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"TableName":"users","Item":{"balance":{"N":"60"},"created_at":{"S":"2024-05-01T19:36:43-05:00"},"id":{"S":"hguzman10@gmail.com"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
60
+ headers:
61
+ Accept-Encoding:
62
+ - ''
63
+ Content-Type:
64
+ - application/x-amz-json-1.0
65
+ X-Amz-Target:
66
+ - DynamoDB_20120810.PutItem
67
+ User-Agent:
68
+ - 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
69
+ md/3.2.3 cfg/retry-mode#legacy
70
+ Host:
71
+ - localhost:8000
72
+ X-Amz-Date:
73
+ - 20240502T003643Z
74
+ X-Amz-Content-Sha256:
75
+ - bce2e7f8fe409b9ee303c60086f066bdcd1046f72262b55b295dec463d74e106
76
+ Authorization:
77
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
78
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
79
+ Signature=66196ff2d65820f4c27935312b8b6a4cbe87288ffceb59025123e77b342f37cf
80
+ Content-Length:
81
+ - '178'
82
+ Accept:
83
+ - "*/*"
84
+ response:
85
+ status:
86
+ code: 200
87
+ message: OK
88
+ headers:
89
+ Date:
90
+ - Thu, 02 May 2024 00:36:43 GMT
91
+ X-Amzn-Requestid:
92
+ - 56298a7a-ad76-45f8-855f-883653ec8f06
93
+ Content-Type:
94
+ - application/x-amz-json-1.0
95
+ X-Amz-Crc32:
96
+ - '2745614147'
97
+ Content-Length:
98
+ - '2'
99
+ Server:
100
+ - Jetty(11.0.17)
101
+ body:
102
+ encoding: UTF-8
103
+ string: "{}"
104
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
105
+ - request:
106
+ method: post
107
+ uri: http://localhost:8000/
108
+ body:
109
+ encoding: UTF-8
110
+ string: '{"TableName":"users","Key":{"id":{"S":"hguzman10@gmail.com"}}}'
111
+ headers:
112
+ Accept-Encoding:
113
+ - ''
114
+ Content-Type:
115
+ - application/x-amz-json-1.0
116
+ X-Amz-Target:
117
+ - DynamoDB_20120810.GetItem
118
+ User-Agent:
119
+ - 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
120
+ md/3.2.3 cfg/retry-mode#legacy
121
+ Host:
122
+ - localhost:8000
123
+ X-Amz-Date:
124
+ - 20240502T003643Z
125
+ X-Amz-Content-Sha256:
126
+ - 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
127
+ Authorization:
128
+ - AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/20240502/us-east-1/dynamodb/aws4_request,
129
+ SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-target,
130
+ Signature=e61f5c53269131bf5f985bfbe1385615456dcedad7ae5fce0fe1ce0a4e854705
131
+ Content-Length:
132
+ - '62'
133
+ Accept:
134
+ - "*/*"
135
+ response:
136
+ status:
137
+ code: 200
138
+ message: OK
139
+ headers:
140
+ Date:
141
+ - Thu, 02 May 2024 00:36:43 GMT
142
+ X-Amzn-Requestid:
143
+ - 8ca63cc3-80f7-4e9e-9fa1-f891ed851802
144
+ Content-Type:
145
+ - application/x-amz-json-1.0
146
+ X-Amz-Crc32:
147
+ - '3547979423'
148
+ Content-Length:
149
+ - '158'
150
+ Server:
151
+ - Jetty(11.0.17)
152
+ body:
153
+ encoding: UTF-8
154
+ string: '{"Item":{"created_at":{"S":"2024-05-01T19:36:43-05:00"},"id":{"S":"hguzman10@gmail.com"},"balance":{"N":"60"},"updated_at":{"S":"2024-05-01T19:36:43-05:00"}}}'
155
+ recorded_at: Thu, 02 May 2024 00:36:43 GMT
156
+ recorded_with: VCR 6.2.0
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.0.2
4
+ version: 0.2.0
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-04-19 00:00:00.000000000 Z
12
+ date: 2024-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -181,14 +181,21 @@ files:
181
181
  - lib/dynamodb_record/persistence.rb
182
182
  - lib/dynamodb_record/query.rb
183
183
  - lib/dynamodb_record/version.rb
184
+ - spec/app/models/authorization.rb
184
185
  - spec/app/models/person.rb
185
186
  - spec/app/models/user.rb
186
187
  - spec/dynamodb_record/document_spec.rb
187
188
  - spec/dynamodb_record/fields_spec.rb
188
189
  - spec/dynamodb_record/finders_spec.rb
190
+ - spec/dynamodb_record/persistence_spec.rb
189
191
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Document/initializes_from_database.yml
190
192
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml
191
193
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml
194
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/_destroy/when_no_range_key/destroys_record.yml
195
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/_destroy/when_there_is_range_key/destroys_record.yml
196
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/does_not_overwrite_existing_record.yml
197
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/saves_record.yml
198
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/updates_record.yml
192
199
  - spec/spec_helper.rb
193
200
  homepage: https://github.com/CarsOk/dynamodb-record
194
201
  licenses:
@@ -214,12 +221,19 @@ signing_key:
214
221
  specification_version: 4
215
222
  summary: A simple DynamoDB ORM
216
223
  test_files:
224
+ - spec/app/models/authorization.rb
217
225
  - spec/app/models/person.rb
218
226
  - spec/app/models/user.rb
219
227
  - spec/dynamodb_record/document_spec.rb
220
228
  - spec/dynamodb_record/fields_spec.rb
221
229
  - spec/dynamodb_record/finders_spec.rb
230
+ - spec/dynamodb_record/persistence_spec.rb
222
231
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Document/initializes_from_database.yml
223
232
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml
224
233
  - spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml
234
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/_destroy/when_no_range_key/destroys_record.yml
235
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/_destroy/when_there_is_range_key/destroys_record.yml
236
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/does_not_overwrite_existing_record.yml
237
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/saves_record.yml
238
+ - spec/fixtures/vcr_cassettes/DynamodbRecord_Persistence/updates_record.yml
225
239
  - spec/spec_helper.rb