mongous 0.1.5 → 0.3.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +216 -44
  3. data/README.ja.adoc +217 -45
  4. data/lib/mongous/base.rb +30 -0
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +55 -46
  7. data/lib/mongous/filter.rb +82 -60
  8. data/lib/mongous/version.rb +1 -1
  9. data/sample/connect_auto_2.rb +2 -1
  10. data/sample/connect_default_2.rb +2 -1
  11. data/sample/connect_environ_2.rb +2 -1
  12. data/sample/connect_loadfile_2.rb +2 -1
  13. data/sample/declare_compact_1.rb +7 -7
  14. data/sample/declare_label_1.rb +10 -6
  15. data/sample/declare_ndex_1.rb +9 -5
  16. data/sample/declare_ndex_2.rb +10 -6
  17. data/sample/declare_strict_1.rb +14 -10
  18. data/sample/declare_strict_2.rb +5 -3
  19. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  20. data/sample/multi_collection_2.rb +63 -0
  21. data/sample/multi_collection_3.rb +26 -0
  22. data/sample/query_basic_1.rb +3 -1
  23. data/sample/query_basic_2.rb +5 -3
  24. data/sample/query_basic_3.rb +2 -3
  25. data/sample/query_basic_4.rb +3 -4
  26. data/sample/query_basic_5.rb +2 -3
  27. data/sample/query_detail_1.rb +3 -1
  28. data/sample/query_detail_2.rb +3 -1
  29. data/sample/query_detail_3.rb +5 -3
  30. data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
  31. data/sample/query_filter_2.rb +50 -0
  32. data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
  33. data/sample/query_projection_1.rb +5 -8
  34. data/sample/query_skip_limit_1.rb +47 -0
  35. data/sample/query_skip_limit_2.rb +49 -0
  36. data/sample/query_sort_order_1.rb +46 -0
  37. data/sample/save_basic_1.rb +1 -2
  38. data/sample/save_basic_2.rb +1 -2
  39. data/sample/save_basic_3.rb +1 -2
  40. data/sample/save_detail_1.rb +7 -4
  41. data/sample/save_detail_2.rb +7 -4
  42. data/sample/save_detail_3.rb +11 -8
  43. data/sample/save_verify_1.rb +7 -4
  44. data/sample/save_verify_3.rb +1 -1
  45. data/sample/save_verify_5.rb +3 -3
  46. data/sample/save_verify_6.rb +3 -3
  47. data/sample/save_verify_7.rb +23 -0
  48. data/sample/update_basic_1.rb +13 -0
  49. data/sample/zap_basic_2.rb +2 -2
  50. data/sample/zap_basic_3.rb +2 -2
  51. data/sample/zbenchmark_search_1.rb +110 -0
  52. data/sample/zbenchmark_search_2.rb +110 -0
  53. metadata +15 -10
  54. data/sample/multi_docs_2.rb +0 -58
  55. data/sample/query_limit_1.rb +0 -44
  56. data/sample/query_order_1.rb +0 -49
  57. data/sample/template_article.rb +0 -5
  58. data/sample/template_person.rb +0 -12
@@ -8,7 +8,7 @@ class Book
8
8
 
9
9
  field :title, :must
10
10
  field :page, Integer, proc{ page > 1 }
11
- field :price, Integer, proc{ (price > 0) & (price < 10_000) }
11
+ field :price, Integer, proc{ (price > 0) && (price < 10_000) }
12
12
 
13
13
  end
14
14
 
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :style, String, ["A4","A5","A6"]
10
+ field :size, String, /[AB]\d/
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title isbn"
16
- book.style = "B5"
15
+ book.title = "title size"
16
+ book.size = "C5"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :price, Integer, (0..1_000_000)
10
+ field :style, String, %w[hardcover softcover paperback]
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title price"
16
- book.price = -1
15
+ book.title = "title style"
16
+ book.style = "newspaper"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -0,0 +1,23 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :price, Integer, (0..1_000_000)
11
+ end
12
+
13
+ begin
14
+ book = Book.new
15
+ book.title = "title price"
16
+ book.price = -1
17
+ book.save
18
+
19
+ rescue => e
20
+ p e.message
21
+
22
+ end
23
+
@@ -0,0 +1,13 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ Book.where( title: /title/ ).each do |book|
11
+ book.price = (book.price || 50 ) * 2
12
+ book.save
13
+ end
@@ -3,9 +3,9 @@ require "mongous"
3
3
 
4
4
  Mongous.connect!
5
5
 
6
- class Book
6
+ class Item
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.filter( title: "title 1" ).delete
10
+ Item.where.delete
11
11
 
@@ -3,9 +3,9 @@ require "mongous"
3
3
 
4
4
  Mongous.connect!
5
5
 
6
- class Book
6
+ class Card
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.filter( title: /title/ ).delete
10
+ Card.delete
11
11
 
@@ -0,0 +1,110 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Card
7
+ include Mongous::Document
8
+ field :i1, Integer
9
+ field :i2, Integer
10
+ field :f1, Float
11
+ field :f2, Float
12
+ field :s1, String
13
+ field :s2, String
14
+ field :d1, Date
15
+ field :d2, Date
16
+ field :t1, Time
17
+ field :t2, Time
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
+ end
25
+
26
+ require "benchmark"
27
+ require "date"
28
+
29
+ COUNT = 10000
30
+
31
+ D0 = Date.parse( "2020-01-01" )
32
+ T0 = D0.to_time
33
+
34
+ Benchmark.bm 32 do |r|
35
+ if COUNT != Card.count
36
+ Card.delete
37
+ r.report "create #{COUNT}" do
38
+ (0...COUNT).each do |i|
39
+ f = i.to_f
40
+ s = i.to_s
41
+ d = D0 + i
42
+ t = T0 + i
43
+ card = Card.create(
44
+ i1: i,
45
+ i2: i,
46
+ f1: f,
47
+ f2: f,
48
+ s1: s,
49
+ s2: s,
50
+ d1: d,
51
+ d2: d,
52
+ t1: t,
53
+ t2: t,
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ r.report "find a integer without index" do
60
+ (0...COUNT).each do |i|
61
+ Card.where( i1: i ).first
62
+ end
63
+ end
64
+ r.report "find a integer with index" do
65
+ (0...COUNT).each do |i|
66
+ Card.where( i2: i ).first
67
+ end
68
+ end
69
+ r.report "find a float without index" do
70
+ (0...COUNT).each do |i|
71
+ Card.where( f1: i.to_f ).first
72
+ end
73
+ end
74
+ r.report "find a float with index" do
75
+ (0...COUNT).each do |i|
76
+ Card.where( f2: i.to_f ).first
77
+ end
78
+ end
79
+ r.report "find a string without index" do
80
+ (0...COUNT).each do |i|
81
+ Card.where( s1: i.to_s ).first
82
+ end
83
+ end
84
+ r.report "find a string with index" do
85
+ (0...COUNT).each do |i|
86
+ Card.where( s2: i.to_s ).first
87
+ end
88
+ end
89
+ r.report "find a date without index" do
90
+ (0...COUNT).each do |i|
91
+ Card.where( d1: D0 + i ).first
92
+ end
93
+ end
94
+ r.report "find a date with index" do
95
+ (0...COUNT).each do |i|
96
+ Card.where( d2: D0 + i ).first
97
+ end
98
+ end
99
+ r.report "find a time without index" do
100
+ (0...COUNT).each do |i|
101
+ Card.where( t1: T0 + i ).first
102
+ end
103
+ end
104
+ r.report "find a time with index" do
105
+ (0...COUNT).each do |i|
106
+ Card.where( t2: T0 + i ).first
107
+ end
108
+ end
109
+ end
110
+
@@ -0,0 +1,110 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Card
7
+ include Mongous::Document
8
+ field :i1, Integer
9
+ field :i2, Integer
10
+ field :f1, Float
11
+ field :f2, Float
12
+ field :s1, String
13
+ field :s2, String
14
+ field :d1, Date
15
+ field :d2, Date
16
+ field :t1, Time
17
+ field :t2, Time
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
+ end
25
+
26
+ require "benchmark"
27
+ require "date"
28
+
29
+ COUNT = 10000
30
+
31
+ D0 = Date.parse( "2020-01-01" )
32
+ T0 = D0.to_time
33
+
34
+ Benchmark.bm 32 do |r|
35
+ if COUNT != Card.count
36
+ Card.delete
37
+ r.report "create #{COUNT}" do
38
+ (0...COUNT).each do |i|
39
+ f = i.to_f
40
+ s = i.to_s
41
+ d = D0 + i
42
+ t = T0 + i
43
+ card = Card.create(
44
+ i1: i,
45
+ i2: i,
46
+ f1: f,
47
+ f2: f,
48
+ s1: s,
49
+ s2: s,
50
+ d1: d,
51
+ d2: d,
52
+ t1: t,
53
+ t2: t,
54
+ )
55
+ end
56
+ end
57
+ end
58
+
59
+ r.report "find range integer without index" do
60
+ (0...COUNT).each do |i|
61
+ Card.where( i1: ( i ... (i+10) ) ).all
62
+ end
63
+ end
64
+ r.report "find range integer with index" do
65
+ (0...COUNT).each do |i|
66
+ Card.where( i2: ( i ... (i+10) ) ).all
67
+ end
68
+ end
69
+ r.report "find range float without index" do
70
+ (0...COUNT).each do |i|
71
+ Card.where( f1: ( i.to_f ... (i+10).to_f ) ).all
72
+ end
73
+ end
74
+ r.report "find range float with index" do
75
+ (0...COUNT).each do |i|
76
+ Card.where( f2: ( i.to_f ... (i+10).to_f ) ).all
77
+ end
78
+ end
79
+ r.report "find range string without index" do
80
+ (0...COUNT).each do |i|
81
+ Card.where( s1: ( i.to_s ... (i+10).to_s ) ).all
82
+ end
83
+ end
84
+ r.report "find range string with index" do
85
+ (0...COUNT).each do |i|
86
+ Card.where( s2: ( i.to_s ... (i+10).to_s ) ).all
87
+ end
88
+ end
89
+ r.report "find range date without index" do
90
+ (0...COUNT).each do |i|
91
+ Card.where( d1: ( (D0 + i) ... (D0 + i + 10) ) ).all
92
+ end
93
+ end
94
+ r.report "find range date with index" do
95
+ (0...COUNT).each do |i|
96
+ Card.where( d2: ( (D0 + i) ... (D0 + i + 10) ) ).all
97
+ end
98
+ end
99
+ r.report "find range time without index" do
100
+ (0...COUNT).each do |i|
101
+ Card.where( t1: ( (T0 + i) ... (T0 + i + 10) ) ).all
102
+ end
103
+ end
104
+ r.report "find range time with index" do
105
+ (0...COUNT).each do |i|
106
+ Card.where( t2: ( (T0 + i) ... (T0 + i + 10) ) ).all
107
+ end
108
+ end
109
+ end
110
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arimay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -90,21 +90,24 @@ files:
90
90
  - sample/declare_ndex_2.rb
91
91
  - sample/declare_strict_1.rb
92
92
  - sample/declare_strict_2.rb
93
- - sample/multi_docs_1.rb
94
- - sample/multi_docs_2.rb
93
+ - sample/multi_collection_1.rb
94
+ - sample/multi_collection_2.rb
95
+ - sample/multi_collection_3.rb
95
96
  - sample/query_basic_1.rb
96
97
  - sample/query_basic_2.rb
97
98
  - sample/query_basic_3.rb
98
99
  - sample/query_basic_4.rb
99
100
  - sample/query_basic_5.rb
100
- - sample/query_basic_6.rb
101
101
  - sample/query_detail_1.rb
102
102
  - sample/query_detail_2.rb
103
103
  - sample/query_detail_3.rb
104
- - sample/query_limit_1.rb
105
- - sample/query_order_1.rb
104
+ - sample/query_filter_1.rb
105
+ - sample/query_filter_2.rb
106
+ - sample/query_find_1.rb
106
107
  - sample/query_projection_1.rb
107
- - sample/query_super_1.rb
108
+ - sample/query_skip_limit_1.rb
109
+ - sample/query_skip_limit_2.rb
110
+ - sample/query_sort_order_1.rb
108
111
  - sample/save_basic_1.rb
109
112
  - sample/save_basic_2.rb
110
113
  - sample/save_basic_3.rb
@@ -117,11 +120,13 @@ files:
117
120
  - sample/save_verify_4.rb
118
121
  - sample/save_verify_5.rb
119
122
  - sample/save_verify_6.rb
120
- - sample/template_article.rb
121
- - sample/template_person.rb
123
+ - sample/save_verify_7.rb
124
+ - sample/update_basic_1.rb
122
125
  - sample/zap_basic_1.rb
123
126
  - sample/zap_basic_2.rb
124
127
  - sample/zap_basic_3.rb
128
+ - sample/zbenchmark_search_1.rb
129
+ - sample/zbenchmark_search_2.rb
125
130
  homepage: https://github.com/arimay/mongous
126
131
  licenses:
127
132
  - MIT
@@ -1,58 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book1
7
- include Mongous::Document
8
- end
9
-
10
- class Book2
11
- include Mongous::Document
12
-
13
- field :title
14
- field :publisher
15
- field :author
16
- field :style
17
- field :price
18
- field :page
19
- field :publish_at
20
- field :isbn
21
- field :lang
22
-
23
- verify :strict
24
- end
25
-
26
- class Book3
27
- include Mongous::Document
28
-
29
- field :title, :must
30
- field :author,
31
- field :publisher,
32
- field :price, Integer, (0..1_000_000)
33
- field :page, Integer, proc{ page > 0 }
34
- field :publish_at, Date, &proc{ Date.today }
35
- field :isbn, proc{ isbn? }
36
- field :lang, &proc{ "ja" }
37
-
38
- verify :strict
39
- verify { having?( title ) }
40
- verify do
41
- having?( author ) | having?( publisher )
42
- end
43
-
44
- def isbn?
45
- isbn&.gsub(/[\D]*/, '').size == 13
46
- end
47
- end
48
-
49
-
50
- pp Book1.fields
51
- puts
52
-
53
- pp Book2.fields
54
- puts
55
-
56
- pp Book3.fields
57
- puts
58
-