mongous 0.2.1 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/README.adoc +176 -26
  4. data/README.ja.adoc +176 -26
  5. data/Rakefile +8 -8
  6. data/_Gemfile.lock +38 -0
  7. data/lib/mongous/base.rb +52 -8
  8. data/lib/mongous/document.rb +21 -10
  9. data/lib/mongous/extention.rb +45 -35
  10. data/lib/mongous/filter.rb +316 -230
  11. data/lib/mongous/version.rb +1 -1
  12. data/mongous.gemspec +4 -4
  13. data/sample/connect_auto_0.rb +9 -0
  14. data/sample/declare_compact_1.rb +5 -8
  15. data/sample/declare_compact_2.rb +38 -0
  16. data/sample/declare_label_1.rb +7 -7
  17. data/sample/declare_ndex_1.rb +6 -6
  18. data/sample/declare_ndex_2.rb +7 -7
  19. data/sample/declare_strict_1.rb +2 -4
  20. data/sample/declare_strict_2.rb +2 -4
  21. data/sample/multi_collection_1.rb +0 -2
  22. data/sample/multi_collection_2.rb +0 -2
  23. data/sample/multi_collection_3.rb +24 -0
  24. data/sample/query_basic_1.rb +10 -4
  25. data/sample/query_basic_2.rb +10 -4
  26. data/sample/query_basic_3.rb +0 -2
  27. data/sample/query_basic_4.rb +0 -2
  28. data/sample/query_basic_5.rb +0 -2
  29. data/sample/query_basic_6.rb +56 -0
  30. data/sample/query_detail_1.rb +2 -3
  31. data/sample/query_detail_2.rb +2 -3
  32. data/sample/query_detail_3.rb +0 -2
  33. data/sample/query_filter_1.rb +0 -2
  34. data/sample/query_filter_2.rb +0 -2
  35. data/sample/query_find_1.rb +14 -13
  36. data/sample/query_select_1.rb +54 -0
  37. data/sample/query_skip_limit_1.rb +17 -16
  38. data/sample/query_skip_limit_2.rb +19 -10
  39. data/sample/query_sort_1.rb +43 -0
  40. data/sample/save_basic_1.rb +1 -5
  41. data/sample/save_basic_2.rb +1 -5
  42. data/sample/save_basic_3.rb +1 -5
  43. data/sample/save_detail_1.rb +0 -2
  44. data/sample/save_detail_2.rb +0 -2
  45. data/sample/save_detail_3.rb +5 -7
  46. data/sample/save_verify_1.rb +2 -4
  47. data/sample/save_verify_2.rb +0 -2
  48. data/sample/save_verify_3.rb +0 -2
  49. data/sample/save_verify_4.rb +0 -2
  50. data/sample/save_verify_5.rb +0 -2
  51. data/sample/save_verify_6.rb +0 -2
  52. data/sample/save_verify_7.rb +0 -2
  53. data/sample/update_basic_1.rb +1 -5
  54. data/sample/zap_basic_1.rb +1 -5
  55. data/sample/zap_basic_2.rb +2 -6
  56. data/sample/zap_basic_3.rb +7 -0
  57. data/sample/zbenchmark_search_1.rb +114 -0
  58. data/sample/zbenchmark_search_2.rb +114 -0
  59. data/sample/zbenchmark_search_3.rb +88 -0
  60. metadata +31 -22
  61. data/.travis.yml +0 -6
  62. data/sample/query_projection_1.rb +0 -41
  63. data/sample/query_sort_order_1.rb +0 -46
@@ -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
 
@@ -13,9 +11,10 @@ class Book
13
11
  field :size
14
12
  field :price
15
13
  field :page
16
- field :publish_at
17
14
  field :isbn
18
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
19
18
 
20
19
  verify :strict
21
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
 
@@ -13,9 +11,10 @@ class Book
13
11
  field :size
14
12
  field :price, Integer
15
13
  field :page, Integer
16
- field :publish_at, Date
17
14
  field :isbn
18
15
  field :lang
16
+ field :created_at, Time
17
+ field :updated_at, Time
19
18
 
20
19
  verify :strict
21
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
 
@@ -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
@@ -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,31 +1,32 @@
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
 
13
- Book.find.each do |book|
14
- p book
10
+ p "Book.find.each do |book|"
11
+ Book.find.each do |a_book|
12
+ p a_book
15
13
  end
16
14
  puts
17
15
 
18
- Book.find( title: /title/ ).each do |book|
19
- p book
16
+ p "Book.find( title: /title/ ).each do |book|"
17
+ Book.find( title: /title/ ).each do |a_book|
18
+ p a_book
20
19
  end
21
20
  puts
22
21
 
23
- Book.find( {}, { projection: {_id: 0} } ).each do |book|
24
- p book
22
+ p "Book.find( {}, { projection: {_id: 0} } ).each do |book|"
23
+ Book.find( {}, { projection: {_id: 0} } ).each do |a_book|
24
+ p a_book
25
25
  end
26
26
  puts
27
27
 
28
- Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
29
- p book
28
+ p "Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|"
29
+ Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |a_book|
30
+ p a_book
30
31
  end
31
32
 
@@ -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,11 +1,7 @@
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
@@ -14,33 +10,38 @@ end
14
10
  end
15
11
  puts
16
12
 
13
+ p "count = Item.count"
17
14
  p count = Item.count
18
15
  puts
19
16
 
20
- p count = Item.where.count
17
+ p "count = Item[0..4].count"
18
+ p count = Item[0..4].count
21
19
  puts
22
20
 
23
- p count = Item.where[0..4].count
21
+ p "count = Item[0...4].count"
22
+ p count = Item[0...4].count
24
23
  puts
25
24
 
26
- p count = Item.where[0...4].count
25
+ p "count = Item[0, 4].count"
26
+ p count = Item[0, 4].count
27
27
  puts
28
28
 
29
- p count = Item.where[0, 4].count
29
+ p "count = Item[5, 5].count"
30
+ p count = Item[5, 5].count
30
31
  puts
31
32
 
32
- p count = Item.where[5, 5].count
33
+ p "books = Item[0, 2].all"
34
+ pp books = Item[0, 2].all
33
35
  puts
34
36
 
35
- pp books = Item.where[0, 2].all
36
- puts
37
-
38
- filter = Item.where
39
- filter[0, 4].each do |item|
37
+ p "Item[0, 4].each do |item|"
38
+ Item[0, 4].each do |item|
40
39
  p item
41
40
  end
42
41
  puts
43
- filter[4, 4].each do |item|
42
+
43
+ p "Item[4, 4].each do |item|"
44
+ Item[4, 4].each do |item|
44
45
  p item
45
46
  end
46
47
  puts
@@ -1,11 +1,7 @@
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
@@ -14,35 +10,48 @@ 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
+
@@ -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 = Book.new
11
7
  book.title = "title basic 1"
@@ -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 = Book.new( title: "title basic 2", author: "Bob", size: "A5", price: 2000, page: 200 )
11
7
  book.save
@@ -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
  doc = { title: "title basic 3", author: "Candy", size: "A6", price: 3000, page: 300 }
11
7
  Book.create( **doc )
@@ -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,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
 
9
7
  field :title, :must
10
8
  field :author
11
9
  field :publisher
12
- field :style, %w[hardcover, softcover, paperback]
10
+ field :style, %w[hardcover softcover paperback]
13
11
  field :size, /[AB]\d/
14
12
  field :price, Integer, (0..1_000_000)
15
13
  field :page, Integer, proc{ page > 0 }
@@ -30,14 +28,14 @@ end
30
28
  book = Book.new
31
29
  book.title = "title detail 3"
32
30
  book.author = "Candy"
33
- #book.publisher
31
+ book.publisher
34
32
  book.style = "paperback"
35
33
  book.size = "A6"
36
34
  book.price = 3000
37
35
  book.page = 300
38
36
  book.isbn = "978-3-16-148410-0"
39
- #book.lang
40
- #book.created_at
41
- #book.updated_at
37
+ # book.lang
38
+ # book.created_at
39
+ # book.updated_at
42
40
  book.save
43
41
 
@@ -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
 
@@ -15,8 +13,8 @@ class Book
15
13
  field :page, Integer, proc{ page > 0 }
16
14
  field :isbn, String, proc{ isbn? }
17
15
  field :lang, String, default: "en"
18
- field :created_at, Time, create: ->(){ Time.now }
19
- 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 }
20
18
 
21
19
  verify :strict
22
20
  verify { having?( title ) }