dynamodb_record 0.0.1 → 0.1.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 +4 -4
- data/Gemfile +0 -5
- data/README.md +6 -3
- data/lib/dynamodb_record/fields.rb +2 -0
- data/lib/dynamodb_record/finders.rb +7 -2
- data/lib/dynamodb_record/persistence.rb +4 -1
- data/lib/dynamodb_record/version.rb +1 -1
- data/spec/app/models/person.rb +2 -0
- data/spec/app/models/user.rb +2 -0
- data/spec/dynamodb_record/document_spec.rb +2 -0
- data/spec/dynamodb_record/fields_spec.rb +7 -1
- data/spec/dynamodb_record/finders_spec.rb +14 -13
- data/spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/finds_record.yml +6 -6
- data/spec/fixtures/vcr_cassettes/DynamodbRecord_Fields/_find/when_record_doesn_t_exists/returns_empty_object.yml +6 -6
- data/spec/spec_helper.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f277db1e3a81f575346f3f0b802259a5bb52a0258b7a63d5e6e674c5c93b8e5c
|
4
|
+
data.tar.gz: d6830c149b35e6d0cd8a38dcb5f1ed4b3c75ec499079450c45f5a038610a0509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a02a723d2213b545a9ab6d5e7e9dd22e514c2868bc62711df3618509d7a6b09011885d626393fa138357db88efbac19bcd46dfcd1d5820e5d5a51f0920f2890b
|
7
|
+
data.tar.gz: 288cfa625378466e04ecba3f22e5e50676f54a732e1b718e81f99f181088ce2786e291ddfd8b6af51a408389dcf53278b7229af081f48ef3731ae7aca2469934
|
data/Gemfile
CHANGED
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 '
|
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
|
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
|
|
@@ -6,15 +6,20 @@ module DynamodbRecord
|
|
6
6
|
|
7
7
|
class_methods do
|
8
8
|
def find(id, range_key = nil)
|
9
|
+
find!(id, range_key)
|
10
|
+
rescue StandardError
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def find!(id, range_key = nil)
|
9
15
|
key = { 'id' => id }
|
10
16
|
|
11
17
|
key[self.range_key] = range_key if self.range_key
|
12
|
-
puts table_name
|
13
18
|
response = client.get_item(
|
14
19
|
table_name:,
|
15
20
|
key:
|
16
21
|
)
|
17
|
-
response.item ? from_database(response.item) :
|
22
|
+
response.item ? from_database(response.item) : raise('Record Not Found')
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -7,7 +7,7 @@ module DynamodbRecord
|
|
7
7
|
|
8
8
|
class_methods do
|
9
9
|
def table_name
|
10
|
-
name = ActiveSupport::Inflector.tableize(base_class.name)
|
10
|
+
name = ActiveSupport::Inflector.tableize(base_class.name).split('/').last
|
11
11
|
@table_name ||= DynamodbRecord::Config.namespace ? "#{DynamodbRecord::Config.namespace}-#{name}" : name
|
12
12
|
end
|
13
13
|
|
@@ -108,6 +108,9 @@ 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 })
|
data/spec/app/models/person.rb
CHANGED
data/spec/app/models/user.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe DynamodbRecord::Fields do
|
@@ -15,9 +17,13 @@ RSpec.describe DynamodbRecord::Fields do
|
|
15
17
|
end
|
16
18
|
expect(Employee.attributes).to eq({ id: { type: :string, options: {} },
|
17
19
|
first_name: { type: :string, options: {} },
|
18
|
-
last_name: { type: :string, options: {} }
|
20
|
+
last_name: { type: :string, options: {} },
|
21
|
+
created_at: { type: :datetime, options: {} },
|
22
|
+
updated_at: { type: :datetime, options: {} }
|
23
|
+
})
|
19
24
|
end
|
20
25
|
|
26
|
+
|
21
27
|
it 'accepts default value' do
|
22
28
|
class City
|
23
29
|
include DynamodbRecord::Document
|
@@ -1,19 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe DynamodbRecord::Fields, :vcr do
|
4
6
|
describe '#find' do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# 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
|
18
19
|
end
|
19
20
|
end
|
@@ -19,13 +19,13 @@ http_interactions:
|
|
19
19
|
Host:
|
20
20
|
- localhost:8000
|
21
21
|
X-Amz-Date:
|
22
|
-
-
|
22
|
+
- 20240426T004444Z
|
23
23
|
X-Amz-Content-Sha256:
|
24
24
|
- 7e2248df156bd85d1c08add1aaa7b84ed6041fe96165fb6879ddbb1424663802
|
25
25
|
Authorization:
|
26
|
-
- AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/
|
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=
|
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,
|
39
|
+
- Fri, 26 Apr 2024 00:44:44 GMT
|
40
40
|
X-Amzn-Requestid:
|
41
|
-
-
|
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,
|
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
|
-
-
|
22
|
+
- 20240426T004553Z
|
23
23
|
X-Amz-Content-Sha256:
|
24
24
|
- acbe242b07a1de9c8a8ac78119a8da7e4bf1d57c7d59ed18930d06ad600c9d6c
|
25
25
|
Authorization:
|
26
|
-
- AWS4-HMAC-SHA256 Credential=AKIAV3OBKSDM5UO5PK5A/
|
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=
|
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,
|
39
|
+
- Fri, 26 Apr 2024 00:45:53 GMT
|
40
40
|
X-Amzn-Requestid:
|
41
|
-
-
|
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,
|
53
|
+
recorded_at: Fri, 26 Apr 2024 00:45:53 GMT
|
54
54
|
recorded_with: VCR 6.2.0
|
data/spec/spec_helper.rb
CHANGED
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
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|