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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bafe4b334f021f466ddd622e5568d05e0b01a3b5524e7ab144b702d8370fbd58
4
- data.tar.gz: 9eab54f02aee3d337c9e714843d397e9de8caf094a0e458964c2aece056bee85
3
+ metadata.gz: f277db1e3a81f575346f3f0b802259a5bb52a0258b7a63d5e6e674c5c93b8e5c
4
+ data.tar.gz: d6830c149b35e6d0cd8a38dcb5f1ed4b3c75ec499079450c45f5a038610a0509
5
5
  SHA512:
6
- metadata.gz: 4f60d3f15b9abf2a73411c6482c4fe0fefa42c386cf61190419d43cbd971b487d8c7d8d0fdd35e710fb3c9229e2e3a5515fd0f41cca682ad30c6d08801e5a460
7
- data.tar.gz: cf7ecd56ff1bd2865c9acefa52c3340ceb7ac3d672a005070b5838f8295564e89e7babc8bf03074c01563396148e92cf975de2e34803d3e9afb85893fc7cd180
6
+ metadata.gz: a02a723d2213b545a9ab6d5e7e9dd22e514c2868bc62711df3618509d7a6b09011885d626393fa138357db88efbac19bcd46dfcd1d5820e5d5a51f0920f2890b
7
+ data.tar.gz: 288cfa625378466e04ecba3f22e5e50676f54a732e1b718e81f99f181088ce2786e291ddfd8b6af51a408389dcf53278b7229af081f48ef3731ae7aca2469934
data/Gemfile CHANGED
@@ -3,8 +3,3 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
-
7
- # group :test do
8
- # gem 'rspec', '~> 3.7'
9
- # gem 'rubocop', '~> 1.62'
10
- # end
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,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) : nil
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 })
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamodbRecord
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Person
2
4
  include DynamodbRecord::Document
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User
2
4
  include DynamodbRecord::Document
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe DynamodbRecord::Document do
@@ -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
- # it 'finds record' do
6
- # user = User.find('hguzman10@gmail.com')
7
- # p user
8
- # expect(user.id).to eq('hguzman10@gmail.com')
9
- # expect(user.balance).to eq(0)
10
- # end
11
- #
12
- # context 'when record doesn\'t exists' do
13
- # it 'returns empty object' do
14
- # user = User.find('not here')
15
- # expect(user).to be_nil
16
- # end
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
- - 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
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dynamodb_record'
2
4
 
3
5
  MODELS = File.join(File.dirname(__FILE__), 'app/models')
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.1
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