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,23 +1,21 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
  end
9
7
 
10
- Book.where( style: %w[A4 A5 A6] ).each do |book|
8
+ Book.where( size: %w[A4 A5 A6] ).each do |book|
11
9
  p book
12
10
  end
13
11
  puts
14
12
 
15
- Book.where( style: %w[A4 A5]).each do |book|
13
+ Book.where( size: %w[A4 A5]).each do |book|
16
14
  p book
17
15
  end
18
16
  puts
19
17
 
20
- Book.where( style: %w[A5] ).each do |book|
18
+ Book.where( size: %w[A5] ).each do |book|
21
19
  p book
22
20
  end
23
21
  puts
@@ -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
  end
@@ -0,0 +1,56 @@
1
+
2
+ # use new syntax from ruby 2.7
3
+
4
+ require "mongous"
5
+
6
+ Mongous.document! :Item
7
+
8
+ (0...10).each do |n|
9
+ unless Item.where( n: n ).first
10
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
11
+ end
12
+ end
13
+ puts
14
+
15
+ p "Item.where( n: (2..5) ).select( _id: 0 ).each do |item|"
16
+ Item.where( n: (2..5) ).select( _id: 0 ).each do |item|
17
+ p item
18
+ end
19
+ puts
20
+
21
+ p "Item.where( n: (2...5) ).select( _id: 0 ).each do |item|"
22
+ Item.where( n: (2...5) ).select( _id: 0 ).each do |item|
23
+ p item
24
+ end
25
+ puts
26
+
27
+ p "Item.where( n: (..5) ).select( _id: 0 ).each do |item|"
28
+ Item.where( n: (..5) ).select( _id: 0 ).each do |item|
29
+ p item
30
+ end
31
+ puts
32
+
33
+ p "Item.where( n: (...5) ).select( _id: 0 ).each do |item|"
34
+ Item.where( n: (...5) ).select( _id: 0 ).each do |item|
35
+ p item
36
+ end
37
+ puts
38
+
39
+ p "Item.where( n: (2..) ).select( _id: 0 ).each do |item|"
40
+ Item.where( n: (2..) ).select( _id: 0 ).each do |item|
41
+ p item
42
+ end
43
+ puts
44
+
45
+ p "Item.not( n: (..2) ).select( _id: 0 ).each do |item|"
46
+ Item.not( n: (..2) ).select( _id: 0 ).each do |item|
47
+ p item
48
+ end
49
+ puts
50
+
51
+ p "Item.select( _id: 0 ).not( n: (..2) ).each do |item|"
52
+ Item.select( _id: 0 ).not( n: (..2) ).each do |item|
53
+ p item
54
+ end
55
+ puts
56
+
@@ -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,11 +8,13 @@ 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
- field :publish_at
16
14
  field :isbn
17
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
18
18
 
19
19
  verify :strict
20
20
  end
@@ -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,11 +8,13 @@ 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
- field :publish_at, Date
16
14
  field :isbn
17
15
  field :lang
16
+ field :created_at, Time
17
+ field :updated_at, Time
18
18
 
19
19
  verify :strict
20
20
  end
@@ -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
 
@@ -1,15 +1,13 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
4
  class Book
7
5
  include Mongous::Document
8
6
  end
9
7
 
10
8
  (1..3).each do |n|
11
9
  unless Book.where( title: "complex #{n}" ).first
12
- Book.create( title: "complex #{n}", author: (0x40 + n).chr, style: "A#{n + 3}", price: n * 1000, page: n * 100 )
10
+ Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
13
11
  end
14
12
  end
15
13
  puts
@@ -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
  filter :title1, { title: /filter/ }
10
8
  filter :price1, { price: (2000..3000) }
11
- filter :page1, where( style: %w[A3 A4] )
9
+ filter :page1, where( size: %w[A3 A4] )
12
10
  end
13
11
 
14
12
  (1..5).each do |n|
15
13
  unless Book.where( title: "filter #{n}" ).first
16
- Book.create( title: "filter #{n}", author: (0x40 + n).chr, style: "A#{n + 3}", price: n * 1000, page: n * 100 )
14
+ Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
17
15
  end
18
16
  end
19
17
  puts
@@ -1,30 +1,31 @@
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
 
6
+ p "book = Book.find.first"
10
7
  p book = Book.find.first
11
8
  puts
12
9
 
10
+ p "Book.find.each do |book|"
13
11
  Book.find.each do |book|
14
12
  p book
15
13
  end
16
14
  puts
17
15
 
16
+ p "Book.find( title: /title/ ).each do |book|"
18
17
  Book.find( title: /title/ ).each do |book|
19
18
  p book
20
19
  end
21
20
  puts
22
21
 
22
+ p "Book.find( {}, { projection: {_id: 0} } ).each do |book|"
23
23
  Book.find( {}, { projection: {_id: 0} } ).each do |book|
24
24
  p book
25
25
  end
26
26
  puts
27
27
 
28
+ p "Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|"
28
29
  Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
29
30
  p book
30
31
  end
@@ -0,0 +1,54 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Label
5
+
6
+ (0...10).each do |n|
7
+ unless Label.where( n: n ).first
8
+ Label.create( n: n, tag: [0x40 + n].pack("C") )
9
+ end
10
+ end
11
+ puts
12
+
13
+ p "Label.each do |label|"
14
+ Label.each do |label|
15
+ p label
16
+ end
17
+ puts
18
+
19
+ p "Label.select( tag: 1 ).each do |label|"
20
+ Label.select( tag: 1 ).each do |label|
21
+ p label
22
+ end
23
+ puts
24
+
25
+ p "Label.select( :tag ).each do |label|"
26
+ Label.select( :tag ).each do |label|
27
+ p label
28
+ end
29
+ puts
30
+
31
+ p "Label.select( _id: 0, n: 1 ).each do |label|"
32
+ Label.select( _id: 0, n: 1 ).each do |label|
33
+ p label
34
+ end
35
+ puts
36
+
37
+ p "Label.select( n: 1, tag: 1 ).each do |label|"
38
+ Label.select( n: 1, tag: 1 ).each do |label|
39
+ p label
40
+ end
41
+ puts
42
+
43
+ p "Label.select( :n, :tag ).each do |label|"
44
+ Label.select( :n, :tag ).each do |label|
45
+ p label
46
+ end
47
+ puts
48
+
49
+ p "Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|"
50
+ Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|
51
+ p label
52
+ end
53
+ puts
54
+
@@ -1,37 +1,48 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
4
+ Mongous.document! :Item
5
5
 
6
- class Book
7
- include Mongous::Document
6
+ (0...10).each do |n|
7
+ unless Item.where( n: n ).first
8
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
9
+ end
8
10
  end
11
+ puts
9
12
 
10
- p count = Book.where.count
13
+ p "count = Item.count"
14
+ p count = Item.count
11
15
  puts
12
16
 
13
- p count = Book.where[0..4].count
17
+ p "count = Item[0..4].count"
18
+ p count = Item[0..4].count
14
19
  puts
15
20
 
16
- p count = Book.where[0...4].count
21
+ p "count = Item[0...4].count"
22
+ p count = Item[0...4].count
17
23
  puts
18
24
 
19
- p count = Book.where[0, 4].count
25
+ p "count = Item[0, 4].count"
26
+ p count = Item[0, 4].count
20
27
  puts
21
28
 
22
- p count = Book.where[5, 5].count
29
+ p "count = Item[5, 5].count"
30
+ p count = Item[5, 5].count
23
31
  puts
24
32
 
25
- pp books = Book.where[0, 2].all
33
+ p "books = Item[0, 2].all"
34
+ pp books = Item[0, 2].all
26
35
  puts
27
36
 
28
- filter = Book.where( title: /title/ )
29
- filter[0, 4].each do |book|
30
- p book
37
+ p "Item[0, 4].each do |item|"
38
+ Item[0, 4].each do |item|
39
+ p item
31
40
  end
32
41
  puts
33
- filter[4, 4].each do |book|
34
- p book
42
+
43
+ p "Item[4, 4].each do |item|"
44
+ Item[4, 4].each do |item|
45
+ p item
35
46
  end
36
47
  puts
37
48
 
@@ -1,48 +1,57 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Item
7
- include Mongous::Document
8
- end
4
+ Mongous.document! :Item
9
5
 
10
6
  (0...10).each do |n|
11
7
  unless Item.where( n: n ).first
12
- Item.create( n: n )
8
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
13
9
  end
14
10
  end
15
11
  puts
16
12
 
13
+ p "Item.each do |item|"
17
14
  Item.each do |item|
18
15
  p item
19
16
  end
20
17
  puts
21
18
 
19
+ #Item.find.skip(2).limit(1).each do |item| p item; end; puts
20
+ p "Item[2].each do |item|"
21
+ Item[2].each do |item|
22
+ p item
23
+ end
24
+ puts
25
+
22
26
  #Item.find.skip(2).each do |item| p item; end; puts
23
- Item.where[2].each do |item|
27
+ p "Item[2, 0].each do |item|"
28
+ Item[2, 0].each do |item|
24
29
  p item
25
30
  end
26
31
  puts
27
32
 
28
33
  #Item.find.limit(3).each do |item| p item; end; puts
29
- Item.where[0,3].each do |item|
34
+ p "Item[0, 3].each do |item|"
35
+ Item[0, 3].each do |item|
30
36
  p item
31
37
  end
32
38
  puts
33
39
 
34
40
  #Item.find.skip(4).limit(5).each do |item| p item; end; puts
35
- Item.where[4,5].each do |item|
41
+ p "Item[4, 5].each do |item|"
42
+ Item[4, 5].each do |item|
36
43
  p item
37
44
  end
38
45
  puts
39
46
 
40
- Item.where[4..8].each do |item|
47
+ p "Item[4..8].each do |item|"
48
+ Item[4..8].each do |item|
41
49
  p item
42
50
  end
43
51
  puts
44
52
 
45
- Item.where[4...9].each do |item|
53
+ p "Item[4...8].each do |item|"
54
+ Item[4...8].each do |item|
46
55
  p item
47
56
  end
48
57
  puts
@@ -0,0 +1,43 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Mash
5
+
6
+ (0...10).each do |n|
7
+ unless Mash.where( n: n ).first
8
+ r = rand
9
+ Mash.create( n: n, r: r )
10
+ end
11
+ end
12
+ puts
13
+
14
+ p "Mash.each do |mash|"
15
+ Mash.each do |mash|
16
+ p mash
17
+ end
18
+ puts
19
+
20
+ p "Mash.sort(r: 1).each do |mash|"
21
+ Mash.sort(r: 1).each do |mash|
22
+ p mash
23
+ end
24
+ puts
25
+
26
+ p "Mash.sort(r: -1).each do |mash|"
27
+ Mash.sort(r: -1).each do |mash|
28
+ p mash
29
+ end
30
+ puts
31
+
32
+ p "Mash.where( n: (3...8) ).sort(r: -1).each do |mash|"
33
+ Mash.where( n: (3...8) ).sort(r: -1).each do |mash|
34
+ p mash
35
+ end
36
+ puts
37
+
38
+ p "Mash.where( n: [0,2,4,6,8] ).sort(r: -1).each do |mash|"
39
+ Mash.where( n: [0,2,4,6,8] ).sort(r: -1).each do |mash|
40
+ p mash
41
+ end
42
+ puts
43
+