mongous 0.2.0 → 0.4.2

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/README.adoc +191 -38
  4. data/README.ja.adoc +192 -39
  5. data/Rakefile +8 -8
  6. data/lib/mongous/base.rb +52 -8
  7. data/lib/mongous/document.rb +36 -13
  8. data/lib/mongous/extention.rb +51 -39
  9. data/lib/mongous/filter.rb +316 -227
  10. data/lib/mongous/version.rb +1 -1
  11. data/mongous.gemspec +4 -4
  12. data/sample/connect_auto_0.rb +9 -0
  13. data/sample/declare_compact_1.rb +6 -8
  14. data/sample/declare_compact_2.rb +38 -0
  15. data/sample/declare_label_1.rb +9 -7
  16. data/sample/declare_ndex_1.rb +8 -6
  17. data/sample/declare_ndex_2.rb +9 -7
  18. data/sample/declare_strict_1.rb +9 -9
  19. data/sample/declare_strict_2.rb +4 -5
  20. data/sample/multi_collection_1.rb +0 -2
  21. data/sample/multi_collection_2.rb +5 -5
  22. data/sample/multi_collection_3.rb +24 -0
  23. data/sample/query_basic_1.rb +8 -2
  24. data/sample/query_basic_2.rb +8 -2
  25. data/sample/query_basic_3.rb +0 -2
  26. data/sample/query_basic_4.rb +3 -5
  27. data/sample/query_basic_5.rb +0 -2
  28. data/sample/query_basic_6.rb +56 -0
  29. data/sample/query_detail_1.rb +3 -3
  30. data/sample/query_detail_2.rb +3 -3
  31. data/sample/query_detail_3.rb +4 -5
  32. data/sample/query_filter_1.rb +1 -3
  33. data/sample/query_filter_2.rb +2 -4
  34. data/sample/query_find_1.rb +6 -5
  35. data/sample/query_select_1.rb +54 -0
  36. data/sample/query_skip_limit_1.rb +25 -14
  37. data/sample/query_skip_limit_2.rb +20 -11
  38. data/sample/query_sort_1.rb +43 -0
  39. data/sample/save_basic_1.rb +2 -6
  40. data/sample/save_basic_2.rb +2 -6
  41. data/sample/save_basic_3.rb +2 -6
  42. data/sample/save_detail_1.rb +3 -3
  43. data/sample/save_detail_2.rb +3 -3
  44. data/sample/save_detail_3.rb +10 -10
  45. data/sample/save_verify_1.rb +6 -6
  46. data/sample/save_verify_2.rb +0 -2
  47. data/sample/save_verify_3.rb +0 -2
  48. data/sample/save_verify_4.rb +0 -2
  49. data/sample/save_verify_5.rb +3 -5
  50. data/sample/save_verify_6.rb +3 -5
  51. data/sample/save_verify_7.rb +21 -0
  52. data/sample/update_basic_1.rb +9 -0
  53. data/sample/zap_basic_1.rb +1 -5
  54. data/sample/zap_basic_2.rb +2 -6
  55. data/sample/zap_basic_3.rb +2 -6
  56. data/sample/zbenchmark_search_1.rb +114 -0
  57. data/sample/zbenchmark_search_2.rb +114 -0
  58. data/sample/zbenchmark_search_3.rb +88 -0
  59. metadata +31 -21
  60. data/sample/query_projection_1.rb +0 -41
  61. data/sample/query_sort_order_1.rb +0 -46
@@ -1,16 +1,12 @@
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
11
7
  book.title = "title basic 1"
12
8
  book.author = "Alice"
13
- book.style = "A4"
9
+ book.size = "A4"
14
10
  book.price = 1000
15
11
  book.page = 100
16
12
  book.save
@@ -1,12 +1,8 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
4
+ Mongous.document! :Book
5
5
 
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
- book = Book.new( title: "title basic 2", author: "Bob", style: "A5", price: 2000, page: 200 )
6
+ book = Book.new( title: "title basic 2", author: "Bob", size: "A5", price: 2000, page: 200 )
11
7
  book.save
12
8
 
@@ -1,12 +1,8 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
4
+ Mongous.document! :Book
5
5
 
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
- doc = { title: "title basic 3", author: "Candy", style: "A6", price: 3000, page: 300 }
6
+ doc = { title: "title basic 3", author: "Candy", size: "A6", price: 3000, page: 300 }
11
7
  Book.create( **doc )
12
8
 
@@ -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
 
@@ -10,6 +8,7 @@ class Book
10
8
  field :author
11
9
  field :publisher
12
10
  field :style
11
+ field :size
13
12
  field :price
14
13
  field :page
15
14
  field :isbn
@@ -24,7 +23,8 @@ book = Book.new
24
23
  book.title = "title detail 1"
25
24
  book.author = "Alice"
26
25
  book.publisher = "Foobar"
27
- book.style = "A4"
26
+ book.style = "hardcover"
27
+ book.size = "A4"
28
28
  book.price = 1000
29
29
  book.page = 100
30
30
  book.isbn = "978-3-16-148410-0"
@@ -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
 
@@ -10,6 +8,7 @@ class Book
10
8
  field :author
11
9
  field :publisher
12
10
  field :style
11
+ field :size
13
12
  field :price, Integer
14
13
  field :page, Integer
15
14
  field :isbn
@@ -24,7 +23,8 @@ book = Book.new
24
23
  book.title = "title detail 2"
25
24
  book.author = "Bob"
26
25
  book.publisher = "Foobar"
27
- book.style = "A5"
26
+ book.style = "softcover"
27
+ book.size = "A5"
28
28
  book.price = 2000
29
29
  book.page = 200
30
30
  book.isbn = "978-3-16-148410-0"
@@ -1,21 +1,20 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, :must
10
8
  field :author
11
9
  field :publisher
12
- field :style, %w[ A4 A5 A6 ]
10
+ field :style, %w[hardcover softcover paperback]
11
+ field :size, /[AB]\d/
13
12
  field :price, Integer, (0..1_000_000)
14
13
  field :page, Integer, proc{ page > 0 }
15
14
  field :isbn, proc{ isbn? }
16
15
  field :lang, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
16
+ field :created_at, Time, create: proc{ Time.now }
17
+ field :updated_at, Time, update: proc{ Time.now }
19
18
 
20
19
  verify :strict
21
20
 
@@ -29,13 +28,14 @@ end
29
28
  book = Book.new
30
29
  book.title = "title detail 3"
31
30
  book.author = "Candy"
32
- #book.publisher
33
- book.style = "A6"
31
+ book.publisher
32
+ book.style = "paperback"
33
+ book.size = "A6"
34
34
  book.price = 3000
35
35
  book.page = 300
36
36
  book.isbn = "978-3-16-148410-0"
37
- #book.lang
38
- #book.created_at
39
- #book.updated_at
37
+ # book.lang
38
+ # book.created_at
39
+ # book.updated_at
40
40
  book.save
41
41
 
@@ -1,21 +1,20 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, String, :must
10
8
  field :author, String
11
9
  field :publisher, String
12
- field :style, String, ["A4","A5","A6"]
10
+ field :style, String, %w[hardcover softcover paperback]
11
+ field :size, String, /[AB]\d/
13
12
  field :price, Integer, (0..1_000_000)
14
13
  field :page, Integer, proc{ page > 0 }
15
14
  field :isbn, String, proc{ isbn? }
16
15
  field :lang, String, default: "en"
17
- field :created_at, Time, create: ->(){ Time.now }
18
- field :updated_at, Time, update: ->(){ Time.now }
16
+ field :created_at, Time, create: proc{ Time.now }
17
+ field :updated_at, Time, update: proc{ Time.now }
19
18
 
20
19
  verify :strict
21
20
  verify { having?( title ) }
@@ -34,7 +33,8 @@ begin
34
33
  book = Book.new
35
34
  book.title = "title verify 1"
36
35
  book.author = "jane doe"
37
- book.style = "A5"
36
+ book.style = "softcover"
37
+ book.size = "A5"
38
38
  book.price = 2000
39
39
  book.page = 200
40
40
  book.isbn = "978-3-16-148410-0"
@@ -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,19 +1,17 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, :must
10
- field :style, String, ["A4","A5","A6"]
8
+ field :size, String, /[AB]\d/
11
9
  end
12
10
 
13
11
  begin
14
12
  book = Book.new
15
- book.title = "title isbn"
16
- book.style = "B5"
13
+ book.title = "title size"
14
+ book.size = "C5"
17
15
  book.save
18
16
 
19
17
  rescue => e
@@ -1,19 +1,17 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
 
9
7
  field :title, :must
10
- field :price, Integer, (0..1_000_000)
8
+ field :style, String, %w[hardcover softcover paperback]
11
9
  end
12
10
 
13
11
  begin
14
12
  book = Book.new
15
- book.title = "title price"
16
- book.price = -1
13
+ book.title = "title style"
14
+ book.style = "newspaper"
17
15
  book.save
18
16
 
19
17
  rescue => e
@@ -0,0 +1,21 @@
1
+
2
+ require "mongous"
3
+
4
+ class Book
5
+ include Mongous::Document
6
+
7
+ field :title, :must
8
+ field :price, Integer, (0..1_000_000)
9
+ end
10
+
11
+ begin
12
+ book = Book.new
13
+ book.title = "title price"
14
+ book.price = -1
15
+ book.save
16
+
17
+ rescue => e
18
+ p e.message
19
+
20
+ end
21
+
@@ -0,0 +1,9 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Book
5
+
6
+ Book.where( title: /title/ ).each do |book|
7
+ book.price = (book.price || 50 ) * 2
8
+ book.save
9
+ end
@@ -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 Book
7
- include Mongous::Document
8
- end
9
-
10
- Book.where( title: "title 1" ).delete
6
+ Item.delete
11
7
 
@@ -1,11 +1,7 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
4
+ Mongous.document! :Card
5
5
 
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
- Book.where( title: /title/ ).delete
6
+ Card.delete
11
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
+