mongous 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +6 -3
  3. data/README.ja.adoc +6 -3
  4. data/lib/mongous/base.rb +12 -2
  5. data/lib/mongous/extention.rb +4 -0
  6. data/lib/mongous/filter.rb +57 -14
  7. data/lib/mongous/version.rb +1 -1
  8. data/sample/connect_auto_0.rb +1 -1
  9. data/sample/declare_compact_1.rb +0 -2
  10. data/sample/declare_compact_2.rb +38 -0
  11. data/sample/declare_label_1.rb +0 -2
  12. data/sample/declare_ndex_1.rb +0 -2
  13. data/sample/declare_ndex_2.rb +0 -2
  14. data/sample/declare_strict_1.rb +0 -2
  15. data/sample/declare_strict_2.rb +0 -2
  16. data/sample/multi_collection_1.rb +0 -2
  17. data/sample/multi_collection_2.rb +0 -2
  18. data/sample/multi_collection_3.rb +6 -8
  19. data/sample/query_basic_1.rb +8 -2
  20. data/sample/query_basic_2.rb +8 -2
  21. data/sample/query_basic_3.rb +0 -2
  22. data/sample/query_basic_4.rb +0 -2
  23. data/sample/query_basic_5.rb +0 -2
  24. data/sample/query_basic_6.rb +56 -0
  25. data/sample/query_detail_1.rb +0 -2
  26. data/sample/query_detail_2.rb +0 -2
  27. data/sample/query_detail_3.rb +0 -2
  28. data/sample/query_filter_1.rb +0 -2
  29. data/sample/query_filter_2.rb +0 -2
  30. data/sample/query_find_1.rb +6 -5
  31. data/sample/query_select_1.rb +8 -5
  32. data/sample/query_skip_limit_1.rb +17 -16
  33. data/sample/query_skip_limit_2.rb +19 -10
  34. data/sample/query_sort_1.rb +43 -0
  35. data/sample/save_basic_1.rb +1 -5
  36. data/sample/save_basic_2.rb +1 -5
  37. data/sample/save_basic_3.rb +1 -5
  38. data/sample/save_detail_1.rb +0 -2
  39. data/sample/save_detail_2.rb +0 -2
  40. data/sample/save_detail_3.rb +0 -2
  41. data/sample/save_verify_1.rb +0 -2
  42. data/sample/save_verify_2.rb +0 -2
  43. data/sample/save_verify_3.rb +0 -2
  44. data/sample/save_verify_4.rb +0 -2
  45. data/sample/save_verify_5.rb +0 -2
  46. data/sample/save_verify_6.rb +0 -2
  47. data/sample/save_verify_7.rb +0 -2
  48. data/sample/update_basic_1.rb +1 -5
  49. data/sample/zap_basic_1.rb +1 -5
  50. data/sample/zap_basic_2.rb +2 -6
  51. data/sample/zap_basic_3.rb +1 -5
  52. data/sample/zbenchmark_search_1.rb +19 -15
  53. data/sample/zbenchmark_search_2.rb +19 -15
  54. data/sample/zbenchmark_search_3.rb +25 -27
  55. metadata +5 -3
  56. data/sample/query_sort_order_1.rb +0 -46
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Book
9
5
 
10
6
  book = Book.new( title: "title basic 2", author: "Bob", size: "A5", price: 2000, page: 200 )
11
7
  book.save
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Book
9
5
 
10
6
  doc = { title: "title basic 3", author: "Candy", size: "A6", price: 3000, page: 300 }
11
7
  Book.create( **doc )
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Book
9
5
 
10
6
  Book.where( title: /title/ ).each do |book|
11
7
  book.price = (book.price || 50 ) * 2
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Book
9
5
 
10
6
  Book.delete
11
7
 
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
4
+ Mongous.document! :Item
5
5
 
6
- class Item
7
- include Mongous::Document
8
- end
9
-
10
- Item.where.delete
6
+ Item.delete
11
7
 
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Card
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Card
9
5
 
10
6
  Card.delete
11
7
 
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Card
7
5
  include Mongous::Document
8
6
  field :i1, Integer
@@ -15,31 +13,35 @@ class Card
15
13
  field :d2, Date
16
14
  field :t1, Time
17
15
  field :t2, Time
16
+ field :r1, Float
17
+ field :r2, Float
18
18
 
19
19
  index :i2, unique: true
20
20
  index :f2, unique: true
21
21
  index :s2, unique: true
22
22
  index :d2, unique: true
23
23
  index :t2, unique: true
24
+ index :r2
24
25
  end
25
26
 
26
27
  require "benchmark"
27
28
  require "date"
28
29
 
29
- COUNT = 10000
30
+ COUNT = 1000
30
31
 
31
32
  D0 = Date.parse( "2020-01-01" )
32
33
  T0 = D0.to_time
33
34
 
34
- Benchmark.bm 32 do |r|
35
+ Benchmark.bm 32 do |bm|
35
36
  if COUNT != Card.count
36
37
  Card.delete
37
- r.report "create #{COUNT}" do
38
+ bm.report "create #{COUNT}" do
38
39
  (0...COUNT).each do |i|
39
40
  f = i.to_f
40
41
  s = i.to_s
41
42
  d = D0 + i
42
43
  t = T0 + i
44
+ r = rand
43
45
  card = Card.create(
44
46
  i1: i,
45
47
  i2: i,
@@ -51,57 +53,59 @@ Benchmark.bm 32 do |r|
51
53
  d2: d,
52
54
  t1: t,
53
55
  t2: t,
56
+ r1: r,
57
+ r2: r,
54
58
  )
55
59
  end
56
60
  end
57
61
  end
58
62
 
59
- r.report "find a integer without index" do
63
+ bm.report "find a integer without index" do
60
64
  (0...COUNT).each do |i|
61
65
  Card.where( i1: i ).first
62
66
  end
63
67
  end
64
- r.report "find a integer with index" do
68
+ bm.report "find a integer with index" do
65
69
  (0...COUNT).each do |i|
66
70
  Card.where( i2: i ).first
67
71
  end
68
72
  end
69
- r.report "find a float without index" do
73
+ bm.report "find a float without index" do
70
74
  (0...COUNT).each do |i|
71
75
  Card.where( f1: i.to_f ).first
72
76
  end
73
77
  end
74
- r.report "find a float with index" do
78
+ bm.report "find a float with index" do
75
79
  (0...COUNT).each do |i|
76
80
  Card.where( f2: i.to_f ).first
77
81
  end
78
82
  end
79
- r.report "find a string without index" do
83
+ bm.report "find a string without index" do
80
84
  (0...COUNT).each do |i|
81
85
  Card.where( s1: i.to_s ).first
82
86
  end
83
87
  end
84
- r.report "find a string with index" do
88
+ bm.report "find a string with index" do
85
89
  (0...COUNT).each do |i|
86
90
  Card.where( s2: i.to_s ).first
87
91
  end
88
92
  end
89
- r.report "find a date without index" do
93
+ bm.report "find a date without index" do
90
94
  (0...COUNT).each do |i|
91
95
  Card.where( d1: D0 + i ).first
92
96
  end
93
97
  end
94
- r.report "find a date with index" do
98
+ bm.report "find a date with index" do
95
99
  (0...COUNT).each do |i|
96
100
  Card.where( d2: D0 + i ).first
97
101
  end
98
102
  end
99
- r.report "find a time without index" do
103
+ bm.report "find a time without index" do
100
104
  (0...COUNT).each do |i|
101
105
  Card.where( t1: T0 + i ).first
102
106
  end
103
107
  end
104
- r.report "find a time with index" do
108
+ bm.report "find a time with index" do
105
109
  (0...COUNT).each do |i|
106
110
  Card.where( t2: T0 + i ).first
107
111
  end
@@ -1,8 +1,6 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Card
7
5
  include Mongous::Document
8
6
  field :i1, Integer
@@ -15,31 +13,35 @@ class Card
15
13
  field :d2, Date
16
14
  field :t1, Time
17
15
  field :t2, Time
16
+ field :r1, Float
17
+ field :r2, Float
18
18
 
19
19
  index :i2, unique: true
20
20
  index :f2, unique: true
21
21
  index :s2, unique: true
22
22
  index :d2, unique: true
23
23
  index :t2, unique: true
24
+ index :r2
24
25
  end
25
26
 
26
27
  require "benchmark"
27
28
  require "date"
28
29
 
29
- COUNT = 10000
30
+ COUNT = 1000
30
31
 
31
32
  D0 = Date.parse( "2020-01-01" )
32
33
  T0 = D0.to_time
33
34
 
34
- Benchmark.bm 32 do |r|
35
+ Benchmark.bm 32 do |bm|
35
36
  if COUNT != Card.count
36
37
  Card.delete
37
- r.report "create #{COUNT}" do
38
+ bm.report "create #{COUNT}" do
38
39
  (0...COUNT).each do |i|
39
40
  f = i.to_f
40
41
  s = i.to_s
41
42
  d = D0 + i
42
43
  t = T0 + i
44
+ r = rand
43
45
  card = Card.create(
44
46
  i1: i,
45
47
  i2: i,
@@ -51,57 +53,59 @@ Benchmark.bm 32 do |r|
51
53
  d2: d,
52
54
  t1: t,
53
55
  t2: t,
56
+ r1: r,
57
+ r2: r,
54
58
  )
55
59
  end
56
60
  end
57
61
  end
58
62
 
59
- r.report "find range integer without index" do
63
+ bm.report "find range integer without index" do
60
64
  (0...COUNT).each do |i|
61
65
  Card.where( i1: ( i ... (i+10) ) ).all
62
66
  end
63
67
  end
64
- r.report "find range integer with index" do
68
+ bm.report "find range integer with index" do
65
69
  (0...COUNT).each do |i|
66
70
  Card.where( i2: ( i ... (i+10) ) ).all
67
71
  end
68
72
  end
69
- r.report "find range float without index" do
73
+ bm.report "find range float without index" do
70
74
  (0...COUNT).each do |i|
71
75
  Card.where( f1: ( i.to_f ... (i+10).to_f ) ).all
72
76
  end
73
77
  end
74
- r.report "find range float with index" do
78
+ bm.report "find range float with index" do
75
79
  (0...COUNT).each do |i|
76
80
  Card.where( f2: ( i.to_f ... (i+10).to_f ) ).all
77
81
  end
78
82
  end
79
- r.report "find range string without index" do
83
+ bm.report "find range string without index" do
80
84
  (0...COUNT).each do |i|
81
85
  Card.where( s1: ( i.to_s ... (i+10).to_s ) ).all
82
86
  end
83
87
  end
84
- r.report "find range string with index" do
88
+ bm.report "find range string with index" do
85
89
  (0...COUNT).each do |i|
86
90
  Card.where( s2: ( i.to_s ... (i+10).to_s ) ).all
87
91
  end
88
92
  end
89
- r.report "find range date without index" do
93
+ bm.report "find range date without index" do
90
94
  (0...COUNT).each do |i|
91
95
  Card.where( d1: ( (D0 + i) ... (D0 + i + 10) ) ).all
92
96
  end
93
97
  end
94
- r.report "find range date with index" do
98
+ bm.report "find range date with index" do
95
99
  (0...COUNT).each do |i|
96
100
  Card.where( d2: ( (D0 + i) ... (D0 + i + 10) ) ).all
97
101
  end
98
102
  end
99
- r.report "find range time without index" do
103
+ bm.report "find range time without index" do
100
104
  (0...COUNT).each do |i|
101
105
  Card.where( t1: ( (T0 + i) ... (T0 + i + 10) ) ).all
102
106
  end
103
107
  end
104
- r.report "find range time with index" do
108
+ bm.report "find range time with index" do
105
109
  (0...COUNT).each do |i|
106
110
  Card.where( t2: ( (T0 + i) ... (T0 + i + 10) ) ).all
107
111
  end
@@ -1,9 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Card
4
+ class Plate
7
5
  include Mongous::Document
8
6
  field :i1, Integer
9
7
  field :i2, Integer
@@ -34,17 +32,17 @@ COUNT = 100000
34
32
  D0 = Date.parse( "2020-01-01" )
35
33
  T0 = D0.to_time
36
34
 
37
- Benchmark.bm 40 do |r|
38
- if COUNT != Card.count
39
- Card.delete
40
- r.report "create #{COUNT}" do
35
+ Benchmark.bm 40 do |bm|
36
+ if COUNT != Plate.count
37
+ Plate.delete
38
+ bm.report "create #{COUNT}" do
41
39
  (0...COUNT).each do |i|
42
40
  f = i.to_f
43
41
  s = i.to_s
44
42
  d = D0 + i
45
43
  t = T0 + i
46
- rn = rand
47
- card = Card.create(
44
+ r = rand
45
+ card = Plate.create(
48
46
  i1: i,
49
47
  i2: i,
50
48
  f1: f,
@@ -55,36 +53,36 @@ Benchmark.bm 40 do |r|
55
53
  d2: d,
56
54
  t1: t,
57
55
  t2: t,
58
- r1: rn,
59
- r2: rn,
56
+ r1: r,
57
+ r2: r,
60
58
  )
61
59
  end
62
60
  end
63
61
  end
64
62
 
65
- r.report "first, order by asc without index" do
66
- Card.where.sort( r1: 1 ).first
63
+ bm.report "first, order by asc without index" do
64
+ Plate.sort( r1: 1 ).first
67
65
  end
68
- r.report "first, order by desc without index" do
69
- Card.where.sort( r1: -1 ).first
66
+ bm.report "first, order by desc without index" do
67
+ Plate.sort( r1: -1 ).first
70
68
  end
71
- r.report "top 10, order by asc without index" do
72
- Card.where.sort( r1: 1 )[0,10].all
69
+ bm.report "top 10, order by asc without index" do
70
+ Plate.sort( r1: 1 )[0,10].all
73
71
  end
74
- r.report "top 10, order by desc without index" do
75
- Card.where.sort( r1: -1 )[0,10].all
72
+ bm.report "top 10, order by desc without index" do
73
+ Plate.sort( r1: -1 )[0,10].all
76
74
  end
77
- r.report "first, order by asc with index" do
78
- Card.where.sort( r2: 1 ).first
75
+ bm.report "first, order by asc with index" do
76
+ Plate.sort( r2: 1 ).first
79
77
  end
80
- r.report "first, order by desc with index" do
81
- Card.where.sort( r2: -1 ).first
78
+ bm.report "first, order by desc with index" do
79
+ Plate.sort( r2: -1 ).first
82
80
  end
83
- r.report "top 10, order by asc with index" do
84
- Card.where.sort( r2: 1 )[0,10].all
81
+ bm.report "top 10, order by asc with index" do
82
+ Plate.sort( r2: 1 )[0,10].all
85
83
  end
86
- r.report "top 10, order by desc with index" do
87
- Card.where.sort( r2: -1 )[0,10].all
84
+ bm.report "top 10, order by desc with index" do
85
+ Plate.sort( r2: -1 )[0,10].all
88
86
  end
89
87
  end
90
88