lotus-dynamodb 0.1.1 → 0.1.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/lotus/dynamodb/version.rb +1 -1
- data/lib/lotus/model/adapters/dynamodb/collection.rb +8 -2
- data/lib/lotus/model/adapters/dynamodb/command.rb +1 -2
- data/lib/lotus/model/adapters/dynamodb/query.rb +29 -3
- data/test/model/adapters/dynamodb_adapter_test.rb +36 -0
- data/test/version_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a025c678317bce959cb08e9fe84d43e17ee8b0f
|
4
|
+
data.tar.gz: 408402f20f9a9e9e523039df3e43114732aa013a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0863ca668599f711306a9a0c144a52b69f0e42f89b4b6397a86797a13fb5111c2f0b52346627ec59bab791707e4dd6c7fd9865f081706c4cd69de4e418da3f2b
|
7
|
+
data.tar.gz: 17ea2d92690e352a795bb6ccc23fb5cfecc6b7422cc6af583f12f5bb663d85baedf00e3c35d674455d4f602ed5e4a865d5b7e548635982b89c923666fb499239
|
data/CHANGELOG.md
CHANGED
@@ -248,7 +248,9 @@ module Lotus
|
|
248
248
|
# @api private
|
249
249
|
# @since 0.1.0
|
250
250
|
def serialize_item(record)
|
251
|
-
Hash[record.
|
251
|
+
Hash[record.delete_if { |_, v| v.nil? }.map do |k, v|
|
252
|
+
[k.to_s, format_attribute_value(v)]
|
253
|
+
end]
|
252
254
|
end
|
253
255
|
|
254
256
|
# Serialize given record or primary key to have proper attributes
|
@@ -282,7 +284,11 @@ module Lotus
|
|
282
284
|
def serialize_attributes(entity)
|
283
285
|
keys = key_schema.keys
|
284
286
|
Hash[entity.reject { |k, _| keys.include?(k) }.map do |k, v|
|
285
|
-
|
287
|
+
if v.nil?
|
288
|
+
[k.to_s, { action: "DELETE" }]
|
289
|
+
else
|
290
|
+
[k.to_s, { value: format_attribute_value(v), action: "PUT" }]
|
291
|
+
end
|
286
292
|
end]
|
287
293
|
end
|
288
294
|
|
@@ -82,7 +82,8 @@ module Lotus
|
|
82
82
|
# @since 0.1.0
|
83
83
|
def all
|
84
84
|
response = run
|
85
|
-
|
85
|
+
|
86
|
+
while continue?(response)
|
86
87
|
@options[:exclusive_start_key] = response.last_evaluated_key
|
87
88
|
response = run(response)
|
88
89
|
end
|
@@ -97,10 +98,11 @@ module Lotus
|
|
97
98
|
# @since 0.1.1
|
98
99
|
def each
|
99
100
|
response = run
|
101
|
+
|
100
102
|
entities = @collection.deserialize(response.entities)
|
101
103
|
entities.each { |x| yield(x) }
|
102
104
|
|
103
|
-
while
|
105
|
+
while continue?(response)
|
104
106
|
response.entities = []
|
105
107
|
|
106
108
|
@options[:exclusive_start_key] = response.last_evaluated_key
|
@@ -474,7 +476,7 @@ module Lotus
|
|
474
476
|
|
475
477
|
response = run
|
476
478
|
|
477
|
-
while
|
479
|
+
while continue?(response)
|
478
480
|
@options[:exclusive_start_key] = response.last_evaluated_key
|
479
481
|
response = run(response)
|
480
482
|
end
|
@@ -590,6 +592,30 @@ module Lotus
|
|
590
592
|
def run(previous_response = nil)
|
591
593
|
@dataset.public_send(operation, @options, previous_response)
|
592
594
|
end
|
595
|
+
|
596
|
+
# Check if request needs to be continued.
|
597
|
+
#
|
598
|
+
# @param previous_response [Response] deserialized response from a previous operation
|
599
|
+
#
|
600
|
+
# @return [Boolean]
|
601
|
+
#
|
602
|
+
# @api private
|
603
|
+
# @since 0.1.2
|
604
|
+
def continue?(previous_response)
|
605
|
+
return false unless previous_response.last_evaluated_key
|
606
|
+
|
607
|
+
if @options[:limit]
|
608
|
+
if @options[:limit] > previous_response.count
|
609
|
+
@options[:limit] = @options[:limit] - previous_response.count
|
610
|
+
|
611
|
+
true
|
612
|
+
else
|
613
|
+
false
|
614
|
+
end
|
615
|
+
else
|
616
|
+
true
|
617
|
+
end
|
618
|
+
end
|
593
619
|
end
|
594
620
|
end
|
595
621
|
end
|
@@ -146,6 +146,15 @@ describe Lotus::Model::Adapters::DynamodbAdapter do
|
|
146
146
|
entity.id.must_equal id
|
147
147
|
@adapter.find(collection, entity.id).must_equal entity
|
148
148
|
end
|
149
|
+
|
150
|
+
it 'removes attribute' do
|
151
|
+
entity.name = nil
|
152
|
+
@adapter.update(collection, entity)
|
153
|
+
|
154
|
+
found_entity = @adapter.find(collection, entity.id)
|
155
|
+
found_entity.must_equal entity
|
156
|
+
found_entity.name.must_be_nil
|
157
|
+
end
|
149
158
|
end
|
150
159
|
|
151
160
|
describe '#delete' do
|
@@ -831,6 +840,33 @@ describe Lotus::Model::Adapters::DynamodbAdapter do
|
|
831
840
|
result.must_equal [purchase1]
|
832
841
|
end
|
833
842
|
end
|
843
|
+
|
844
|
+
describe 'with large records set' do
|
845
|
+
before do
|
846
|
+
purchases.each do |entity|
|
847
|
+
@adapter.create(collection, entity)
|
848
|
+
end
|
849
|
+
end
|
850
|
+
|
851
|
+
let(:purchases) do
|
852
|
+
25.times.map do |i|
|
853
|
+
TestPurchase.new(
|
854
|
+
region: 'europe',
|
855
|
+
content: ('A'..'Z').to_a[i]*50_000,
|
856
|
+
created_at: Time.new,
|
857
|
+
)
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
it 'returns all of them' do
|
862
|
+
query = Proc.new {
|
863
|
+
where(region: 'europe').limit(24)
|
864
|
+
}
|
865
|
+
|
866
|
+
result = @adapter.query(collection, &query).count
|
867
|
+
result.must_equal 24
|
868
|
+
end
|
869
|
+
end
|
834
870
|
end
|
835
871
|
|
836
872
|
describe 'exists?' do
|
data/test/version_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lotus-dynamodb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Krasnoukhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lotus-model
|