dynamodb_record 0.0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 390ba8516fb8b5a58b440693b38162fc36139bb5e20f017b40569a0dc7033d16
4
- data.tar.gz: d849dfa255097beb3b8872a05bf896e3c1bd2f630461b1db700306c09ac1a365
3
+ metadata.gz: f277db1e3a81f575346f3f0b802259a5bb52a0258b7a63d5e6e674c5c93b8e5c
4
+ data.tar.gz: d6830c149b35e6d0cd8a38dcb5f1ed4b3c75ec499079450c45f5a038610a0509
5
5
  SHA512:
6
- metadata.gz: d53e86c92d9e94eb5999e8ba5b781903b57876b6727aa33dc513f87c0b628cbd1a4ab47b55ecd67b18da9e60b236df4f1af79a65c36121875a6e4c5d07938142
7
- data.tar.gz: de1b46d33ae75d0450f82e9b8c30549f0bfc884ebe107c235390e84895d3a24b1aadde5e466a671b8ad8454c0574fd818168dc47dae6ef0d1d36e5dd75d81389
6
+ metadata.gz: a02a723d2213b545a9ab6d5e7e9dd22e514c2868bc62711df3618509d7a6b09011885d626393fa138357db88efbac19bcd46dfcd1d5820e5d5a51f0920f2890b
7
+ data.tar.gz: 288cfa625378466e04ecba3f22e5e50676f54a732e1b718e81f99f181088ce2786e291ddfd8b6af51a408389dcf53278b7229af081f48ef3731ae7aca2469934
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
 
@@ -11,6 +11,8 @@ module DynamodbRecord
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
@@ -6,6 +6,12 @@ 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
@@ -13,7 +19,7 @@ module DynamodbRecord
13
19
  table_name:,
14
20
  key:
15
21
  )
16
- response.item ? from_database(response.item) : nil
22
+ response.item ? from_database(response.item) : raise('Record Not Found')
17
23
  end
18
24
  end
19
25
  end
@@ -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 })
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamodbRecord
4
- VERSION = '0.0.2'
4
+ VERSION = '0.1.0'
5
5
  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
@@ -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
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.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-19 00:00:00.000000000 Z
12
+ date: 2024-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport