simple_record 1.3.3 → 1.3.4
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.
- data/lib/simple_record.rb +10 -0
- data/test/test_results_array.rb +13 -0
- data/test/test_simple_record.rb +1 -0
- metadata +4 -4
data/lib/simple_record.rb
CHANGED
@@ -229,6 +229,7 @@ module SimpleRecord
|
|
229
229
|
end
|
230
230
|
|
231
231
|
def has_id_on_end(name_s)
|
232
|
+
name_s = name_s.to_s
|
232
233
|
name_s.length > 3 && name_s[-3..-1] == "_id"
|
233
234
|
end
|
234
235
|
|
@@ -804,6 +805,8 @@ module SimpleRecord
|
|
804
805
|
# Query example:
|
805
806
|
# MyModel.find(:all, :conditions=>["name = ?", name], :order=>"created desc", :limit=>10)
|
806
807
|
#
|
808
|
+
# Extra options:
|
809
|
+
# :per_token => the number of results to return per next_token, max is 2500.
|
807
810
|
def self.find(*params)
|
808
811
|
#puts 'params=' + params.inspect
|
809
812
|
q_type = :all
|
@@ -820,6 +823,13 @@ module SimpleRecord
|
|
820
823
|
#puts 'options=' + options.inspect
|
821
824
|
#puts 'after collect=' + options.inspect
|
822
825
|
convert_condition_params(options)
|
826
|
+
per_token = options[:per_token]
|
827
|
+
if per_token
|
828
|
+
op_dup = options.dup
|
829
|
+
op_dup[:limit] = per_token # simpledb uses Limit as a paging thing, not what is normal
|
830
|
+
params[1] = op_dup
|
831
|
+
end
|
832
|
+
|
823
833
|
end
|
824
834
|
# puts 'params2=' + params.inspect
|
825
835
|
|
data/test/test_results_array.rb
CHANGED
@@ -19,10 +19,12 @@ class TestResultsArray < TestBase
|
|
19
19
|
# ensures that it uses next token and what not
|
20
20
|
def test_big_result
|
21
21
|
i = TestHelpers.clear_out_my_models
|
22
|
+
SimpleRecord.stats.clear
|
22
23
|
num_made = 110
|
23
24
|
num_made.times do |i|
|
24
25
|
mm = MyModel.create(:name=>"Travis", :age=>i, :cool=>true)
|
25
26
|
end
|
27
|
+
assert SimpleRecord.stats.saves == num_made
|
26
28
|
rs = MyModel.find(:all) # should get 100 at a time
|
27
29
|
assert rs.size == num_made
|
28
30
|
i = 0
|
@@ -30,15 +32,26 @@ class TestResultsArray < TestBase
|
|
30
32
|
#puts 'x=' + x.id
|
31
33
|
i+=1
|
32
34
|
end
|
35
|
+
assert SimpleRecord.stats.selects == 3 # one for count.
|
33
36
|
assert i == num_made
|
34
37
|
# running through all the results twice to ensure it works properly after lazy loading complete.
|
38
|
+
SimpleRecord.stats.clear
|
35
39
|
i = 0
|
36
40
|
rs.each do |x|
|
37
41
|
#puts 'x=' + x.id
|
38
42
|
i+=1
|
39
43
|
end
|
44
|
+
assert SimpleRecord.stats.selects == 0
|
40
45
|
assert i == num_made
|
41
46
|
end
|
47
|
+
|
48
|
+
def test_limit
|
49
|
+
SimpleRecord.stats.clear
|
50
|
+
rs = MyModel.find(:all, :per_token=>2500)
|
51
|
+
assert rs.size == 110
|
52
|
+
assert SimpleRecord.stats.selects == 1, "SimpleRecord.stats.selects is #{SimpleRecord.stats.selects}"
|
53
|
+
|
54
|
+
end
|
42
55
|
|
43
56
|
|
44
57
|
end
|
data/test/test_simple_record.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 4
|
10
|
+
version: 1.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-05-
|
20
|
+
date: 2010-05-27 00:00:00 -07:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|