mongous 0.1.6 → 0.4.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +296 -46
  3. data/README.ja.adoc +297 -47
  4. data/lib/mongous/base.rb +35 -2
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +72 -57
  7. data/lib/mongous/filter.rb +273 -208
  8. data/lib/mongous/version.rb +1 -1
  9. data/mongous.gemspec +1 -1
  10. data/sample/connect_auto_0.rb +9 -0
  11. data/sample/connect_auto_2.rb +2 -1
  12. data/sample/connect_default_2.rb +2 -1
  13. data/sample/connect_environ_2.rb +2 -1
  14. data/sample/connect_loadfile_2.rb +2 -1
  15. data/sample/declare_compact_1.rb +7 -7
  16. data/sample/declare_label_1.rb +10 -6
  17. data/sample/declare_ndex_1.rb +9 -5
  18. data/sample/declare_ndex_2.rb +10 -6
  19. data/sample/declare_strict_1.rb +14 -10
  20. data/sample/declare_strict_2.rb +5 -3
  21. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  22. data/sample/multi_collection_2.rb +63 -0
  23. data/sample/multi_collection_3.rb +26 -0
  24. data/sample/query_basic_1.rb +3 -1
  25. data/sample/query_basic_2.rb +5 -3
  26. data/sample/query_basic_3.rb +2 -3
  27. data/sample/query_basic_4.rb +3 -4
  28. data/sample/query_basic_5.rb +2 -3
  29. data/sample/query_detail_1.rb +3 -1
  30. data/sample/query_detail_2.rb +3 -1
  31. data/sample/query_detail_3.rb +5 -3
  32. data/sample/{query_basic_6.rb → query_filter_1.rb} +7 -4
  33. data/sample/query_filter_2.rb +50 -0
  34. data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
  35. data/sample/query_select_1.rb +51 -0
  36. data/sample/query_skip_limit_1.rb +47 -0
  37. data/sample/query_skip_limit_2.rb +49 -0
  38. data/sample/query_sort_order_1.rb +46 -0
  39. data/sample/save_basic_1.rb +1 -2
  40. data/sample/save_basic_2.rb +1 -2
  41. data/sample/save_basic_3.rb +1 -2
  42. data/sample/save_detail_1.rb +7 -4
  43. data/sample/save_detail_2.rb +7 -4
  44. data/sample/save_detail_3.rb +11 -8
  45. data/sample/save_verify_1.rb +7 -4
  46. data/sample/save_verify_3.rb +1 -1
  47. data/sample/save_verify_5.rb +3 -3
  48. data/sample/save_verify_6.rb +3 -3
  49. data/sample/save_verify_7.rb +23 -0
  50. data/sample/update_basic_1.rb +13 -0
  51. data/sample/zap_basic_2.rb +2 -2
  52. data/sample/zap_basic_3.rb +2 -2
  53. data/sample/zbenchmark_search_1.rb +110 -0
  54. data/sample/zbenchmark_search_2.rb +110 -0
  55. data/sample/zbenchmark_search_3.rb +90 -0
  56. metadata +19 -12
  57. data/sample/multi_docs_2.rb +0 -58
  58. data/sample/query_limit_1.rb +0 -44
  59. data/sample/query_order_1.rb +0 -49
  60. data/sample/query_projection_1.rb +0 -44
  61. data/sample/template_article.rb +0 -5
  62. data/sample/template_person.rb +0 -12
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, String, :must
10
10
  field :author, String
11
11
  field :publisher, String
12
- field :style, String, ["A4","A5","A6"]
12
+ field :style, String, %w[hardcover softcover paperback]
13
+ field :size, String, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
- field :date, Date, &proc{ Date.today }
15
15
  field :page, Integer, proc{ page > 0 }
16
16
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
17
+ field :lang, String, default: "en"
18
+ field :created_at, Time, create: proc{ Time.now }
19
+ field :updated_at, Time, update: proc{ Time.now }
18
20
 
19
21
  verify :strict
20
22
  verify { having?( title ) }
@@ -33,7 +35,8 @@ begin
33
35
  book = Book.new
34
36
  book.title = "title verify 1"
35
37
  book.author = "jane doe"
36
- book.style = "A5"
38
+ book.style = "softcover"
39
+ book.size = "A5"
37
40
  book.price = 2000
38
41
  book.page = 200
39
42
  book.isbn = "978-3-16-148410-0"
@@ -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
+
@@ -0,0 +1,90 @@
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
+ field :r1, Float
19
+ field :r2, Float
20
+
21
+ index :i2, unique: true
22
+ index :f2, unique: true
23
+ index :s2, unique: true
24
+ index :d2, unique: true
25
+ index :t2, unique: true
26
+ index :r2
27
+ end
28
+
29
+ require "benchmark"
30
+ require "date"
31
+
32
+ COUNT = 100000
33
+
34
+ D0 = Date.parse( "2020-01-01" )
35
+ T0 = D0.to_time
36
+
37
+ Benchmark.bm 40 do |r|
38
+ if COUNT != Card.count
39
+ Card.delete
40
+ r.report "create #{COUNT}" do
41
+ (0...COUNT).each do |i|
42
+ f = i.to_f
43
+ s = i.to_s
44
+ d = D0 + i
45
+ t = T0 + i
46
+ rn = rand
47
+ card = Card.create(
48
+ i1: i,
49
+ i2: i,
50
+ f1: f,
51
+ f2: f,
52
+ s1: s,
53
+ s2: s,
54
+ d1: d,
55
+ d2: d,
56
+ t1: t,
57
+ t2: t,
58
+ r1: rn,
59
+ r2: rn,
60
+ )
61
+ end
62
+ end
63
+ end
64
+
65
+ r.report "first, order by asc without index" do
66
+ Card.where.sort( r1: 1 ).first
67
+ end
68
+ r.report "first, order by desc without index" do
69
+ Card.where.sort( r1: -1 ).first
70
+ end
71
+ r.report "top 10, order by asc without index" do
72
+ Card.where.sort( r1: 1 )[0,10].all
73
+ end
74
+ r.report "top 10, order by desc without index" do
75
+ Card.where.sort( r1: -1 )[0,10].all
76
+ end
77
+ r.report "first, order by asc with index" do
78
+ Card.where.sort( r2: 1 ).first
79
+ end
80
+ r.report "first, order by desc with index" do
81
+ Card.where.sort( r2: -1 ).first
82
+ end
83
+ r.report "top 10, order by asc with index" do
84
+ Card.where.sort( r2: 1 )[0,10].all
85
+ end
86
+ r.report "top 10, order by desc with index" do
87
+ Card.where.sort( r2: -1 )[0,10].all
88
+ end
89
+ end
90
+