mongous 0.2.1 → 0.4.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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/README.adoc +176 -26
  4. data/README.ja.adoc +176 -26
  5. data/Rakefile +8 -8
  6. data/_Gemfile.lock +38 -0
  7. data/lib/mongous/base.rb +52 -8
  8. data/lib/mongous/document.rb +21 -10
  9. data/lib/mongous/extention.rb +45 -35
  10. data/lib/mongous/filter.rb +316 -230
  11. data/lib/mongous/version.rb +1 -1
  12. data/mongous.gemspec +4 -4
  13. data/sample/connect_auto_0.rb +9 -0
  14. data/sample/declare_compact_1.rb +5 -8
  15. data/sample/declare_compact_2.rb +38 -0
  16. data/sample/declare_label_1.rb +7 -7
  17. data/sample/declare_ndex_1.rb +6 -6
  18. data/sample/declare_ndex_2.rb +7 -7
  19. data/sample/declare_strict_1.rb +2 -4
  20. data/sample/declare_strict_2.rb +2 -4
  21. data/sample/multi_collection_1.rb +0 -2
  22. data/sample/multi_collection_2.rb +0 -2
  23. data/sample/multi_collection_3.rb +24 -0
  24. data/sample/query_basic_1.rb +10 -4
  25. data/sample/query_basic_2.rb +10 -4
  26. data/sample/query_basic_3.rb +0 -2
  27. data/sample/query_basic_4.rb +0 -2
  28. data/sample/query_basic_5.rb +0 -2
  29. data/sample/query_basic_6.rb +56 -0
  30. data/sample/query_detail_1.rb +2 -3
  31. data/sample/query_detail_2.rb +2 -3
  32. data/sample/query_detail_3.rb +0 -2
  33. data/sample/query_filter_1.rb +0 -2
  34. data/sample/query_filter_2.rb +0 -2
  35. data/sample/query_find_1.rb +14 -13
  36. data/sample/query_select_1.rb +54 -0
  37. data/sample/query_skip_limit_1.rb +17 -16
  38. data/sample/query_skip_limit_2.rb +19 -10
  39. data/sample/query_sort_1.rb +43 -0
  40. data/sample/save_basic_1.rb +1 -5
  41. data/sample/save_basic_2.rb +1 -5
  42. data/sample/save_basic_3.rb +1 -5
  43. data/sample/save_detail_1.rb +0 -2
  44. data/sample/save_detail_2.rb +0 -2
  45. data/sample/save_detail_3.rb +5 -7
  46. data/sample/save_verify_1.rb +2 -4
  47. data/sample/save_verify_2.rb +0 -2
  48. data/sample/save_verify_3.rb +0 -2
  49. data/sample/save_verify_4.rb +0 -2
  50. data/sample/save_verify_5.rb +0 -2
  51. data/sample/save_verify_6.rb +0 -2
  52. data/sample/save_verify_7.rb +0 -2
  53. data/sample/update_basic_1.rb +1 -5
  54. data/sample/zap_basic_1.rb +1 -5
  55. data/sample/zap_basic_2.rb +2 -6
  56. data/sample/zap_basic_3.rb +7 -0
  57. data/sample/zbenchmark_search_1.rb +114 -0
  58. data/sample/zbenchmark_search_2.rb +114 -0
  59. data/sample/zbenchmark_search_3.rb +88 -0
  60. metadata +31 -22
  61. data/.travis.yml +0 -6
  62. data/sample/query_projection_1.rb +0 -41
  63. data/sample/query_sort_order_1.rb +0 -46
@@ -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
 
@@ -0,0 +1,7 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Card
5
+
6
+ Card.delete
7
+
@@ -0,0 +1,114 @@
1
+
2
+ require "mongous"
3
+
4
+ class Card
5
+ include Mongous::Document
6
+ field :i1, Integer
7
+ field :i2, Integer
8
+ field :f1, Float
9
+ field :f2, Float
10
+ field :s1, String
11
+ field :s2, String
12
+ field :d1, Date
13
+ field :d2, Date
14
+ field :t1, Time
15
+ field :t2, Time
16
+ field :r1, Float
17
+ field :r2, Float
18
+
19
+ index :i2, unique: true
20
+ index :f2, unique: true
21
+ index :s2, unique: true
22
+ index :d2, unique: true
23
+ index :t2, unique: true
24
+ index :r2
25
+ end
26
+
27
+ require "benchmark"
28
+ require "date"
29
+
30
+ COUNT = 1000
31
+
32
+ D0 = Date.parse( "2020-01-01" )
33
+ T0 = D0.to_time
34
+
35
+ Benchmark.bm 32 do |bm|
36
+ if COUNT != Card.count
37
+ Card.delete
38
+ bm.report "create #{COUNT}" do
39
+ (0...COUNT).each do |i|
40
+ f = i.to_f
41
+ s = i.to_s
42
+ d = D0 + i
43
+ t = T0 + i
44
+ r = rand
45
+ card = Card.create(
46
+ i1: i,
47
+ i2: i,
48
+ f1: f,
49
+ f2: f,
50
+ s1: s,
51
+ s2: s,
52
+ d1: d,
53
+ d2: d,
54
+ t1: t,
55
+ t2: t,
56
+ r1: r,
57
+ r2: r,
58
+ )
59
+ end
60
+ end
61
+ end
62
+
63
+ bm.report "find a integer without index" do
64
+ (0...COUNT).each do |i|
65
+ Card.where( i1: i ).first
66
+ end
67
+ end
68
+ bm.report "find a integer with index" do
69
+ (0...COUNT).each do |i|
70
+ Card.where( i2: i ).first
71
+ end
72
+ end
73
+ bm.report "find a float without index" do
74
+ (0...COUNT).each do |i|
75
+ Card.where( f1: i.to_f ).first
76
+ end
77
+ end
78
+ bm.report "find a float with index" do
79
+ (0...COUNT).each do |i|
80
+ Card.where( f2: i.to_f ).first
81
+ end
82
+ end
83
+ bm.report "find a string without index" do
84
+ (0...COUNT).each do |i|
85
+ Card.where( s1: i.to_s ).first
86
+ end
87
+ end
88
+ bm.report "find a string with index" do
89
+ (0...COUNT).each do |i|
90
+ Card.where( s2: i.to_s ).first
91
+ end
92
+ end
93
+ bm.report "find a date without index" do
94
+ (0...COUNT).each do |i|
95
+ Card.where( d1: D0 + i ).first
96
+ end
97
+ end
98
+ bm.report "find a date with index" do
99
+ (0...COUNT).each do |i|
100
+ Card.where( d2: D0 + i ).first
101
+ end
102
+ end
103
+ bm.report "find a time without index" do
104
+ (0...COUNT).each do |i|
105
+ Card.where( t1: T0 + i ).first
106
+ end
107
+ end
108
+ bm.report "find a time with index" do
109
+ (0...COUNT).each do |i|
110
+ Card.where( t2: T0 + i ).first
111
+ end
112
+ end
113
+ end
114
+
@@ -0,0 +1,114 @@
1
+
2
+ require "mongous"
3
+
4
+ class Card
5
+ include Mongous::Document
6
+ field :i1, Integer
7
+ field :i2, Integer
8
+ field :f1, Float
9
+ field :f2, Float
10
+ field :s1, String
11
+ field :s2, String
12
+ field :d1, Date
13
+ field :d2, Date
14
+ field :t1, Time
15
+ field :t2, Time
16
+ field :r1, Float
17
+ field :r2, Float
18
+
19
+ index :i2, unique: true
20
+ index :f2, unique: true
21
+ index :s2, unique: true
22
+ index :d2, unique: true
23
+ index :t2, unique: true
24
+ index :r2
25
+ end
26
+
27
+ require "benchmark"
28
+ require "date"
29
+
30
+ COUNT = 1000
31
+
32
+ D0 = Date.parse( "2020-01-01" )
33
+ T0 = D0.to_time
34
+
35
+ Benchmark.bm 32 do |bm|
36
+ if COUNT != Card.count
37
+ Card.delete
38
+ bm.report "create #{COUNT}" do
39
+ (0...COUNT).each do |i|
40
+ f = i.to_f
41
+ s = i.to_s
42
+ d = D0 + i
43
+ t = T0 + i
44
+ r = rand
45
+ card = Card.create(
46
+ i1: i,
47
+ i2: i,
48
+ f1: f,
49
+ f2: f,
50
+ s1: s,
51
+ s2: s,
52
+ d1: d,
53
+ d2: d,
54
+ t1: t,
55
+ t2: t,
56
+ r1: r,
57
+ r2: r,
58
+ )
59
+ end
60
+ end
61
+ end
62
+
63
+ bm.report "find range integer without index" do
64
+ (0...COUNT).each do |i|
65
+ Card.where( i1: ( i ... (i+10) ) ).all
66
+ end
67
+ end
68
+ bm.report "find range integer with index" do
69
+ (0...COUNT).each do |i|
70
+ Card.where( i2: ( i ... (i+10) ) ).all
71
+ end
72
+ end
73
+ bm.report "find range float without index" do
74
+ (0...COUNT).each do |i|
75
+ Card.where( f1: ( i.to_f ... (i+10).to_f ) ).all
76
+ end
77
+ end
78
+ bm.report "find range float with index" do
79
+ (0...COUNT).each do |i|
80
+ Card.where( f2: ( i.to_f ... (i+10).to_f ) ).all
81
+ end
82
+ end
83
+ bm.report "find range string without index" do
84
+ (0...COUNT).each do |i|
85
+ Card.where( s1: ( i.to_s ... (i+10).to_s ) ).all
86
+ end
87
+ end
88
+ bm.report "find range string with index" do
89
+ (0...COUNT).each do |i|
90
+ Card.where( s2: ( i.to_s ... (i+10).to_s ) ).all
91
+ end
92
+ end
93
+ bm.report "find range date without index" do
94
+ (0...COUNT).each do |i|
95
+ Card.where( d1: ( (D0 + i) ... (D0 + i + 10) ) ).all
96
+ end
97
+ end
98
+ bm.report "find range date with index" do
99
+ (0...COUNT).each do |i|
100
+ Card.where( d2: ( (D0 + i) ... (D0 + i + 10) ) ).all
101
+ end
102
+ end
103
+ bm.report "find range time without index" do
104
+ (0...COUNT).each do |i|
105
+ Card.where( t1: ( (T0 + i) ... (T0 + i + 10) ) ).all
106
+ end
107
+ end
108
+ bm.report "find range time with index" do
109
+ (0...COUNT).each do |i|
110
+ Card.where( t2: ( (T0 + i) ... (T0 + i + 10) ) ).all
111
+ end
112
+ end
113
+ end
114
+
@@ -0,0 +1,88 @@
1
+
2
+ require "mongous"
3
+
4
+ class Plate
5
+ include Mongous::Document
6
+ field :i1, Integer
7
+ field :i2, Integer
8
+ field :f1, Float
9
+ field :f2, Float
10
+ field :s1, String
11
+ field :s2, String
12
+ field :d1, Date
13
+ field :d2, Date
14
+ field :t1, Time
15
+ field :t2, Time
16
+ field :r1, Float
17
+ field :r2, Float
18
+
19
+ index :i2, unique: true
20
+ index :f2, unique: true
21
+ index :s2, unique: true
22
+ index :d2, unique: true
23
+ index :t2, unique: true
24
+ index :r2
25
+ end
26
+
27
+ require "benchmark"
28
+ require "date"
29
+
30
+ COUNT = 100000
31
+
32
+ D0 = Date.parse( "2020-01-01" )
33
+ T0 = D0.to_time
34
+
35
+ Benchmark.bm 40 do |bm|
36
+ if COUNT != Plate.count
37
+ Plate.delete
38
+ bm.report "create #{COUNT}" do
39
+ (0...COUNT).each do |i|
40
+ f = i.to_f
41
+ s = i.to_s
42
+ d = D0 + i
43
+ t = T0 + i
44
+ r = rand
45
+ card = Plate.create(
46
+ i1: i,
47
+ i2: i,
48
+ f1: f,
49
+ f2: f,
50
+ s1: s,
51
+ s2: s,
52
+ d1: d,
53
+ d2: d,
54
+ t1: t,
55
+ t2: t,
56
+ r1: r,
57
+ r2: r,
58
+ )
59
+ end
60
+ end
61
+ end
62
+
63
+ bm.report "first, order by asc without index" do
64
+ Plate.sort( r1: 1 ).first
65
+ end
66
+ bm.report "first, order by desc without index" do
67
+ Plate.sort( r1: -1 ).first
68
+ end
69
+ bm.report "top 10, order by asc without index" do
70
+ Plate.sort( r1: 1 )[0,10].all
71
+ end
72
+ bm.report "top 10, order by desc without index" do
73
+ Plate.sort( r1: -1 )[0,10].all
74
+ end
75
+ bm.report "first, order by asc with index" do
76
+ Plate.sort( r2: 1 ).first
77
+ end
78
+ bm.report "first, order by desc with index" do
79
+ Plate.sort( r2: -1 ).first
80
+ end
81
+ bm.report "top 10, order by asc with index" do
82
+ Plate.sort( r2: 1 )[0,10].all
83
+ end
84
+ bm.report "top 10, order by desc with index" do
85
+ Plate.sort( r2: -1 )[0,10].all
86
+ end
87
+ end
88
+
metadata CHANGED
@@ -1,58 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - arimay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-08 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.13'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.13'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '12.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '12.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description: " Yet another lightweight mongo wrapper library. "
54
+ version: '0'
55
+ description: " Yet another mongo wrapper library. "
56
56
  email:
57
57
  - arima.yasuhiro@gmail.com
58
58
  executables: []
@@ -61,11 +61,12 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
- - ".travis.yml"
64
+ - ".rubocop.yml"
65
65
  - Gemfile
66
66
  - README.adoc
67
67
  - README.ja.adoc
68
68
  - Rakefile
69
+ - _Gemfile.lock
69
70
  - bin/console
70
71
  - bin/setup
71
72
  - lib/mongous.rb
@@ -75,6 +76,7 @@ files:
75
76
  - lib/mongous/filter.rb
76
77
  - lib/mongous/version.rb
77
78
  - mongous.gemspec
79
+ - sample/connect_auto_0.rb
78
80
  - sample/connect_auto_1.rb
79
81
  - sample/connect_auto_2.rb
80
82
  - sample/connect_default_1.rb
@@ -85,6 +87,7 @@ files:
85
87
  - sample/connect_loadfile_2.rb
86
88
  - sample/connect_mongo.yml
87
89
  - sample/declare_compact_1.rb
90
+ - sample/declare_compact_2.rb
88
91
  - sample/declare_label_1.rb
89
92
  - sample/declare_ndex_1.rb
90
93
  - sample/declare_ndex_2.rb
@@ -92,21 +95,23 @@ files:
92
95
  - sample/declare_strict_2.rb
93
96
  - sample/multi_collection_1.rb
94
97
  - sample/multi_collection_2.rb
98
+ - sample/multi_collection_3.rb
95
99
  - sample/query_basic_1.rb
96
100
  - sample/query_basic_2.rb
97
101
  - sample/query_basic_3.rb
98
102
  - sample/query_basic_4.rb
99
103
  - sample/query_basic_5.rb
104
+ - sample/query_basic_6.rb
100
105
  - sample/query_detail_1.rb
101
106
  - sample/query_detail_2.rb
102
107
  - sample/query_detail_3.rb
103
108
  - sample/query_filter_1.rb
104
109
  - sample/query_filter_2.rb
105
110
  - sample/query_find_1.rb
106
- - sample/query_projection_1.rb
111
+ - sample/query_select_1.rb
107
112
  - sample/query_skip_limit_1.rb
108
113
  - sample/query_skip_limit_2.rb
109
- - sample/query_sort_order_1.rb
114
+ - sample/query_sort_1.rb
110
115
  - sample/save_basic_1.rb
111
116
  - sample/save_basic_2.rb
112
117
  - sample/save_basic_3.rb
@@ -123,11 +128,15 @@ files:
123
128
  - sample/update_basic_1.rb
124
129
  - sample/zap_basic_1.rb
125
130
  - sample/zap_basic_2.rb
131
+ - sample/zap_basic_3.rb
132
+ - sample/zbenchmark_search_1.rb
133
+ - sample/zbenchmark_search_2.rb
134
+ - sample/zbenchmark_search_3.rb
126
135
  homepage: https://github.com/arimay/mongous
127
136
  licenses:
128
137
  - MIT
129
138
  metadata: {}
130
- post_install_message:
139
+ post_install_message:
131
140
  rdoc_options: []
132
141
  require_paths:
133
142
  - lib
@@ -142,8 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
151
  - !ruby/object:Gem::Version
143
152
  version: '0'
144
153
  requirements: []
145
- rubygems_version: 3.1.4
146
- signing_key:
154
+ rubygems_version: 3.2.3
155
+ signing_key:
147
156
  specification_version: 4
148
157
  summary: Mongo wrapper library.
149
158
  test_files: []