mongous 0.1.8 → 0.4.1

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +286 -48
  3. data/README.ja.adoc +288 -50
  4. data/lib/mongous/base.rb +45 -2
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +74 -55
  7. data/lib/mongous/filter.rb +316 -233
  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/declare_compact_1.rb +7 -9
  12. data/sample/declare_compact_2.rb +38 -0
  13. data/sample/declare_label_1.rb +10 -8
  14. data/sample/declare_ndex_1.rb +9 -7
  15. data/sample/declare_ndex_2.rb +10 -8
  16. data/sample/declare_strict_1.rb +14 -12
  17. data/sample/declare_strict_2.rb +5 -5
  18. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -2
  19. data/sample/multi_collection_2.rb +61 -0
  20. data/sample/multi_collection_3.rb +24 -0
  21. data/sample/query_basic_1.rb +8 -3
  22. data/sample/query_basic_2.rb +11 -6
  23. data/sample/query_basic_3.rb +2 -5
  24. data/sample/query_basic_4.rb +3 -6
  25. data/sample/query_basic_5.rb +2 -5
  26. data/sample/query_basic_6.rb +35 -22
  27. data/sample/query_detail_1.rb +3 -3
  28. data/sample/query_detail_2.rb +3 -3
  29. data/sample/query_detail_3.rb +5 -5
  30. data/sample/query_filter_1.rb +44 -0
  31. data/sample/query_filter_2.rb +48 -0
  32. data/sample/{query_super_1.rb → query_find_1.rb} +6 -6
  33. data/sample/query_select_1.rb +54 -0
  34. data/sample/query_skip_limit_1.rb +48 -0
  35. data/sample/query_skip_limit_2.rb +58 -0
  36. data/sample/query_sort_1.rb +43 -0
  37. data/sample/save_basic_1.rb +2 -7
  38. data/sample/save_basic_2.rb +2 -7
  39. data/sample/save_basic_3.rb +2 -7
  40. data/sample/save_detail_1.rb +7 -6
  41. data/sample/save_detail_2.rb +7 -6
  42. data/sample/save_detail_3.rb +11 -10
  43. data/sample/save_verify_1.rb +7 -6
  44. data/sample/save_verify_2.rb +0 -2
  45. data/sample/save_verify_3.rb +1 -3
  46. data/sample/save_verify_4.rb +0 -2
  47. data/sample/save_verify_5.rb +3 -5
  48. data/sample/save_verify_6.rb +3 -5
  49. data/sample/save_verify_7.rb +21 -0
  50. data/sample/update_basic_1.rb +9 -0
  51. data/sample/zap_basic_1.rb +1 -5
  52. data/sample/zap_basic_2.rb +2 -6
  53. data/sample/zap_basic_3.rb +2 -6
  54. data/sample/zbenchmark_search_1.rb +114 -0
  55. data/sample/zbenchmark_search_2.rb +114 -0
  56. data/sample/zbenchmark_search_3.rb +88 -0
  57. metadata +20 -12
  58. data/sample/multi_docs_2.rb +0 -58
  59. data/sample/query_basic_7.rb +0 -38
  60. data/sample/query_limit_1.rb +0 -44
  61. data/sample/query_order_1.rb +0 -49
  62. data/sample/query_projection_1.rb +0 -44
  63. data/sample/template_article.rb +0 -5
  64. data/sample/template_person.rb +0 -12
@@ -1,23 +1,28 @@
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
 
8
+ p "book = Book.where( title: /title/ ).first"
9
+ p book = Book.where( title: /title/ ).first
10
+ puts
10
11
 
11
- p book = Book.filter( title: /title/ ).first
12
+ p "book = Book.where( title: /title/ ).last"
13
+ p book = Book.where( title: /title/ ).last
12
14
  puts
13
15
 
14
- p count = Book.filter( title: /title/ ).count
16
+ p "count = Book.where( title: /title/ ).count"
17
+ p count = Book.where( title: /title/ ).count
15
18
  puts
16
19
 
17
- pp books = Book.filter( title: /title/ ).all
20
+ p "books = Book.where( title: /title/ ).all"
21
+ pp books = Book.where( title: /title/ ).all
18
22
  puts
19
23
 
20
- Book.filter( title: /title/ ).each do |book|
24
+ p "Book.where( title: /title/ ).each do |book|"
25
+ Book.where( title: /title/ ).each do |book|
21
26
  p book
22
27
  end
23
28
  puts
@@ -1,19 +1,16 @@
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
-
11
- Book.filter.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
8
+ Book.where.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
12
9
  p book
13
10
  end
14
11
  puts
15
12
 
16
- Book.filter( title: /title/ ).option( projection: {_id: 0, title: 1} ).each do |book|
13
+ Book.where( title: /title/ ).option( projection: {_id: 0, title: 1} ).each do |book|
17
14
  p book
18
15
  end
19
16
 
@@ -1,24 +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
-
11
- Book.filter( style: %w[A4 A5 A6] ).each do |book|
8
+ Book.where( size: %w[A4 A5 A6] ).each do |book|
12
9
  p book
13
10
  end
14
11
  puts
15
12
 
16
- Book.filter( style: %w[A4 A5]).each do |book|
13
+ Book.where( size: %w[A4 A5]).each do |book|
17
14
  p book
18
15
  end
19
16
  puts
20
17
 
21
- Book.filter( style: %w[A5] ).each do |book|
18
+ Book.where( size: %w[A5] ).each do |book|
22
19
  p book
23
20
  end
24
21
  puts
@@ -1,19 +1,16 @@
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
-
11
- Book.filter( page: (100..300) ).each do |book|
8
+ Book.where( page: (100..300) ).each do |book|
12
9
  p book
13
10
  end
14
11
  puts
15
12
 
16
- Book.filter( page: (100...300) ).each do |book|
13
+ Book.where( page: (100...300) ).each do |book|
17
14
  p book
18
15
  end
19
16
  puts
@@ -1,43 +1,56 @@
1
1
 
2
+ # use new syntax from ruby 2.7
3
+
2
4
  require "mongous"
3
5
 
4
- Mongous.connect!
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
5
14
 
6
- class Book
7
- include Mongous::Document
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
8
18
  end
19
+ puts
9
20
 
10
- Book.new( title: "complex 1", author: "Alice", style: "A4", price: 1000, page: 100 ).save
11
- Book.new( title: "complex 2", author: "Bob", style: "A5", price: 2000, page: 200 ).save
12
- Book.new( title: "complex 3", author: "Candy", style: "A6", price: 3000, page: 300 ).save
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
13
26
 
14
- filter1 = Book.filter( title: /comp/ )
15
- filter2 = Book.not( price: (2000...3000) )
16
- filter3 = Book.and( filter1, filter2 ).select( _id: 0 )
17
- filter4 = Book.or( filter1, filter2 ).select( _id: 0 )
18
- p filter1.to_condition
19
- p filter2.to_condition
20
- p filter3.to_condition
21
- p filter4.to_condition
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
22
31
  puts
23
32
 
24
- filter1.each do |book|
25
- p book
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
26
36
  end
27
37
  puts
28
38
 
29
- filter2.each do |book|
30
- p book
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
31
42
  end
32
43
  puts
33
44
 
34
- filter3.each do |book|
35
- p book
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
36
48
  end
37
49
  puts
38
50
 
39
- filter4.each do |book|
40
- p book
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
41
54
  end
42
55
  puts
43
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,20 +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
- field :publish_at, Date, &proc{ Date.today }
16
14
  field :isbn, proc{ isbn? }
17
- field :lang, &proc{ "ja" }
15
+ field :lang, default: "en"
16
+ field :created_at, Time, create: proc{ Time.now }
17
+ field :updated_at, Time, update: proc{ Time.now }
18
18
 
19
19
  verify :strict
20
20
 
@@ -0,0 +1,44 @@
1
+
2
+ require "mongous"
3
+
4
+ class Book
5
+ include Mongous::Document
6
+ end
7
+
8
+ (1..3).each do |n|
9
+ unless Book.where( title: "complex #{n}" ).first
10
+ Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
11
+ end
12
+ end
13
+ puts
14
+
15
+ filter1 = Book.where( title: /comp/ )
16
+ filter2 = Book.not( price: (2000...3000) )
17
+ filter3 = Book.and( filter1, filter2 ).select( _id: 0 )
18
+ filter4 = Book.or( filter1, filter2 ).select( _id: 0 )
19
+ p filter1.to_condition
20
+ p filter2.to_condition
21
+ p filter3.to_condition
22
+ p filter4.to_condition
23
+ puts
24
+
25
+ filter1.each do |book|
26
+ p book
27
+ end
28
+ puts
29
+
30
+ filter2.each do |book|
31
+ p book
32
+ end
33
+ puts
34
+
35
+ filter3.each do |book|
36
+ p book
37
+ end
38
+ puts
39
+
40
+ filter4.each do |book|
41
+ p book
42
+ end
43
+ puts
44
+
@@ -0,0 +1,48 @@
1
+
2
+ require "mongous"
3
+
4
+ class Book
5
+ include Mongous::Document
6
+
7
+ filter :title1, { title: /filter/ }
8
+ filter :price1, { price: (2000..3000) }
9
+ filter :page1, where( size: %w[A3 A4] )
10
+ end
11
+
12
+ (1..5).each do |n|
13
+ unless Book.where( title: "filter #{n}" ).first
14
+ Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
15
+ end
16
+ end
17
+ puts
18
+
19
+ filter1 = Book.where( :price1 )
20
+ filter2 = Book.not( :page1 )
21
+ filter3 = Book.and( :title1, filter1, filter2 ).select( _id: 0 )
22
+ filter4 = Book.and( :title1, Book.or( filter1, filter2 ) ).select( _id: 0 )
23
+ p filter1.to_condition
24
+ p filter2.to_condition
25
+ p filter3.to_condition
26
+ p filter4.to_condition
27
+ puts
28
+
29
+ filter1.each do |book|
30
+ p book
31
+ end
32
+ puts
33
+
34
+ filter2.each do |book|
35
+ p book
36
+ end
37
+ puts
38
+
39
+ filter3.each do |book|
40
+ p book
41
+ end
42
+ puts
43
+
44
+ filter4.each do |book|
45
+ p book
46
+ end
47
+ puts
48
+
@@ -1,31 +1,31 @@
1
1
 
2
2
  require "mongous"
3
3
 
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
9
-
4
+ Mongous.document! :Book
10
5
 
6
+ p "book = Book.find.first"
11
7
  p book = Book.find.first
12
8
  puts
13
9
 
10
+ p "Book.find.each do |book|"
14
11
  Book.find.each do |book|
15
12
  p book
16
13
  end
17
14
  puts
18
15
 
16
+ p "Book.find( title: /title/ ).each do |book|"
19
17
  Book.find( title: /title/ ).each do |book|
20
18
  p book
21
19
  end
22
20
  puts
23
21
 
22
+ p "Book.find( {}, { projection: {_id: 0} } ).each do |book|"
24
23
  Book.find( {}, { projection: {_id: 0} } ).each do |book|
25
24
  p book
26
25
  end
27
26
  puts
28
27
 
28
+ p "Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|"
29
29
  Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
30
30
  p book
31
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
+