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
@@ -7,13 +7,12 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- Book.filter( page: (100..300) ).each do |book|
10
+ Book.where( page: (100..300) ).each do |book|
12
11
  p book
13
12
  end
14
13
  puts
15
14
 
16
- Book.filter( page: (100...300) ).each do |book|
15
+ Book.where( page: (100...300) ).each do |book|
17
16
  p book
18
17
  end
19
18
  puts
@@ -10,11 +10,13 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
21
  verify :strict
20
22
  end
@@ -10,11 +10,13 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price, Integer
14
15
  field :page, Integer
15
- field :publish_at, Date
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at, Time
19
+ field :updated_at, Time
18
20
 
19
21
  verify :strict
20
22
  end
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, :must
10
10
  field :author
11
11
  field :publisher
12
- field :style, %w[ A4 A5 A6 ]
12
+ field :style, %w[hardcover softcover paperback]
13
+ field :size, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page > 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
16
  field :isbn, proc{ isbn? }
17
- field :lang, &proc{ "ja" }
17
+ field :lang, 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
 
@@ -7,11 +7,14 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
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
10
+ (1..3).each do |n|
11
+ unless Book.where( title: "complex #{n}" ).first
12
+ Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
13
+ end
14
+ end
15
+ puts
13
16
 
14
- filter1 = Book.filter( title: /comp/ )
17
+ filter1 = Book.where( title: /comp/ )
15
18
  filter2 = Book.not( price: (2000...3000) )
16
19
  filter3 = Book.and( filter1, filter2 ).select( _id: 0 )
17
20
  filter4 = Book.or( filter1, filter2 ).select( _id: 0 )
@@ -0,0 +1,50 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ filter :title1, { title: /filter/ }
10
+ filter :price1, { price: (2000..3000) }
11
+ filter :page1, where( size: %w[A3 A4] )
12
+ end
13
+
14
+ (1..5).each do |n|
15
+ unless Book.where( title: "filter #{n}" ).first
16
+ Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
17
+ end
18
+ end
19
+ puts
20
+
21
+ filter1 = Book.where( :price1 )
22
+ filter2 = Book.not( :page1 )
23
+ filter3 = Book.and( :title1, filter1, filter2 ).select( _id: 0 )
24
+ filter4 = Book.and( :title1, Book.or( filter1, filter2 ) ).select( _id: 0 )
25
+ p filter1.to_condition
26
+ p filter2.to_condition
27
+ p filter3.to_condition
28
+ p filter4.to_condition
29
+ puts
30
+
31
+ filter1.each do |book|
32
+ p book
33
+ end
34
+ puts
35
+
36
+ filter2.each do |book|
37
+ p book
38
+ end
39
+ puts
40
+
41
+ filter3.each do |book|
42
+ p book
43
+ end
44
+ puts
45
+
46
+ filter4.each do |book|
47
+ p book
48
+ end
49
+ puts
50
+
@@ -7,7 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  p book = Book.find.first
12
11
  puts
13
12
 
@@ -0,0 +1,51 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Label
7
+ include Mongous::Document
8
+ end
9
+
10
+ (0...10).each do |n|
11
+ unless Label.where( n: n ).first
12
+ Label.create( n: n, tag: [0x40 + n].pack("C") )
13
+ end
14
+ end
15
+ puts
16
+
17
+ Label.each do |label|
18
+ p label
19
+ end
20
+ puts
21
+
22
+ Label.select( tag: 1 ).each do |label|
23
+ p label
24
+ end
25
+ puts
26
+
27
+ Label.select( :tag ).each do |label|
28
+ p label
29
+ end
30
+ puts
31
+
32
+ Label.select( _id: 0, n: 1 ).each do |label|
33
+ p label
34
+ end
35
+ puts
36
+
37
+ Label.select( n: 1, tag: 1 ).each do |label|
38
+ p label
39
+ end
40
+ puts
41
+
42
+ Label.select( :n, :tag ).each do |label|
43
+ p label
44
+ end
45
+ puts
46
+
47
+ Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|
48
+ p label
49
+ end
50
+ puts
51
+
@@ -0,0 +1,47 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Item
7
+ include Mongous::Document
8
+ end
9
+
10
+ (0...10).each do |n|
11
+ unless Item.where( n: n ).first
12
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
13
+ end
14
+ end
15
+ puts
16
+
17
+ p count = Item.count
18
+ puts
19
+
20
+ p count = Item.where.count
21
+ puts
22
+
23
+ p count = Item.where[0..4].count
24
+ puts
25
+
26
+ p count = Item.where[0...4].count
27
+ puts
28
+
29
+ p count = Item.where[0, 4].count
30
+ puts
31
+
32
+ p count = Item.where[5, 5].count
33
+ puts
34
+
35
+ pp books = Item.where[0, 2].all
36
+ puts
37
+
38
+ filter = Item.where
39
+ filter[0, 4].each do |item|
40
+ p item
41
+ end
42
+ puts
43
+ filter[4, 4].each do |item|
44
+ p item
45
+ end
46
+ puts
47
+
@@ -0,0 +1,49 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Item
7
+ include Mongous::Document
8
+ end
9
+
10
+ (0...10).each do |n|
11
+ unless Item.where( n: n ).first
12
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
13
+ end
14
+ end
15
+ puts
16
+
17
+ Item.each do |item|
18
+ p item
19
+ end
20
+ puts
21
+
22
+ #Item.find.skip(2).each do |item| p item; end; puts
23
+ Item.where[2].each do |item|
24
+ p item
25
+ end
26
+ puts
27
+
28
+ #Item.find.limit(3).each do |item| p item; end; puts
29
+ Item.where[0,3].each do |item|
30
+ p item
31
+ end
32
+ puts
33
+
34
+ #Item.find.skip(4).limit(5).each do |item| p item; end; puts
35
+ Item.where[4,5].each do |item|
36
+ p item
37
+ end
38
+ puts
39
+
40
+ Item.where[4..8].each do |item|
41
+ p item
42
+ end
43
+ puts
44
+
45
+ Item.where[4...9].each do |item|
46
+ p item
47
+ end
48
+ puts
49
+
@@ -0,0 +1,46 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Item
7
+ include Mongous::Document
8
+ end
9
+
10
+ (0...10).each do |n|
11
+ unless Item.where( n: n ).first
12
+ Item.create( n: n )
13
+ end
14
+ end
15
+ puts
16
+
17
+ Item.each do |item|
18
+ p item
19
+ end
20
+ puts
21
+
22
+ Item.where.sort(n: 1).each do |item|
23
+ p item
24
+ end
25
+ puts
26
+
27
+ Item.where.sort(n: -1).each do |item|
28
+ p item
29
+ end
30
+ puts
31
+
32
+ Item.where.order(n: -1).each do |item|
33
+ p item
34
+ end
35
+ puts
36
+
37
+ Item.where( n: (3...8) ).order(n: -1).each do |item|
38
+ p item
39
+ end
40
+ puts
41
+
42
+ Item.where( n: [0,2,4,6,8] ).order(n: -1).each do |item|
43
+ p item
44
+ end
45
+ puts
46
+
@@ -7,11 +7,10 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  book = Book.new
12
11
  book.title = "title basic 1"
13
12
  book.author = "Alice"
14
- book.style = "A4"
13
+ book.size = "A4"
15
14
  book.price = 1000
16
15
  book.page = 100
17
16
  book.save
@@ -7,7 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- book = Book.new( title: "title basic 2", author: "Bob", style: "A5", price: 2000, page: 200 )
10
+ book = Book.new( title: "title basic 2", author: "Bob", size: "A5", price: 2000, page: 200 )
12
11
  book.save
13
12
 
@@ -7,7 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
- doc = { title: "title basic 3", author: "Candy", style: "A6", price: 3000, page: 300 }
10
+ doc = { title: "title basic 3", author: "Candy", size: "A6", price: 3000, page: 300 }
12
11
  Book.create( **doc )
13
12
 
@@ -10,25 +10,28 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price
14
15
  field :page
15
- field :publish_at
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at
19
+ field :updated_at
18
20
 
19
21
  verify :strict
20
22
  end
21
23
 
22
-
23
24
  book = Book.new
24
25
  book.title = "title detail 1"
25
26
  book.author = "Alice"
26
27
  book.publisher = "Foobar"
27
- book.style = "A4"
28
+ book.style = "hardcover"
29
+ book.size = "A4"
28
30
  book.price = 1000
29
31
  book.page = 100
30
- book.publish_at = Date.today
31
32
  book.isbn = "978-3-16-148410-0"
32
33
  book.lang = "en"
34
+ book.created_at = Time.now
35
+ book.updated_at = Time.now
33
36
  book.save
34
37
 
@@ -10,25 +10,28 @@ class Book
10
10
  field :author
11
11
  field :publisher
12
12
  field :style
13
+ field :size
13
14
  field :price, Integer
14
15
  field :page, Integer
15
- field :publish_at, Date
16
16
  field :isbn
17
17
  field :lang
18
+ field :created_at, Time
19
+ field :updated_at, Time
18
20
 
19
21
  verify :strict
20
22
  end
21
23
 
22
-
23
24
  book = Book.new
24
25
  book.title = "title detail 2"
25
26
  book.author = "Bob"
26
27
  book.publisher = "Foobar"
27
- book.style = "A5"
28
+ book.style = "softcover"
29
+ book.size = "A5"
28
30
  book.price = 2000
29
31
  book.page = 200
30
- book.publish_at = Date.today
31
32
  book.isbn = "978-3-16-148410-0"
32
33
  book.lang = "en"
34
+ book.created_at = Time.now
35
+ book.updated_at = Time.now
33
36
  book.save
34
37
 
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, :must
10
10
  field :author
11
11
  field :publisher
12
- field :style, %w[ A4 A5 A6 ]
12
+ field :style, %w[hardcover, softcover, paperback]
13
+ field :size, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
15
  field :page, Integer, proc{ page > 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
16
  field :isbn, proc{ isbn? }
17
- field :lang, &proc{ "ja" }
17
+ field :lang, 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
 
@@ -25,16 +27,17 @@ class Book
25
27
  end
26
28
  end
27
29
 
28
-
29
30
  book = Book.new
30
31
  book.title = "title detail 3"
31
32
  book.author = "Candy"
32
- #book.publisher = "Foobar"
33
- book.style = "A6"
33
+ book.publisher
34
+ book.style = "paperback"
35
+ book.size = "A6"
34
36
  book.price = 3000
35
37
  book.page = 300
36
- #book.publish_at = Date.today
37
38
  book.isbn = "978-3-16-148410-0"
38
- #book.lang
39
+ # book.lang
40
+ # book.created_at
41
+ # book.updated_at
39
42
  book.save
40
43