mongous 0.1.8 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,48 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Item
5
+
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
10
+ end
11
+ puts
12
+
13
+ p "count = Item.count"
14
+ p count = Item.count
15
+ puts
16
+
17
+ p "count = Item[0..4].count"
18
+ p count = Item[0..4].count
19
+ puts
20
+
21
+ p "count = Item[0...4].count"
22
+ p count = Item[0...4].count
23
+ puts
24
+
25
+ p "count = Item[0, 4].count"
26
+ p count = Item[0, 4].count
27
+ puts
28
+
29
+ p "count = Item[5, 5].count"
30
+ p count = Item[5, 5].count
31
+ puts
32
+
33
+ p "books = Item[0, 2].all"
34
+ pp books = Item[0, 2].all
35
+ puts
36
+
37
+ p "Item[0, 4].each do |item|"
38
+ Item[0, 4].each do |item|
39
+ p item
40
+ end
41
+ puts
42
+
43
+ p "Item[4, 4].each do |item|"
44
+ Item[4, 4].each do |item|
45
+ p item
46
+ end
47
+ puts
48
+
@@ -0,0 +1,58 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Item
5
+
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
10
+ end
11
+ puts
12
+
13
+ p "Item.each do |item|"
14
+ Item.each do |item|
15
+ p item
16
+ end
17
+ puts
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
+
26
+ #Item.find.skip(2).each do |item| p item; end; puts
27
+ p "Item[2, 0].each do |item|"
28
+ Item[2, 0].each do |item|
29
+ p item
30
+ end
31
+ puts
32
+
33
+ #Item.find.limit(3).each do |item| p item; end; puts
34
+ p "Item[0, 3].each do |item|"
35
+ Item[0, 3].each do |item|
36
+ p item
37
+ end
38
+ puts
39
+
40
+ #Item.find.skip(4).limit(5).each do |item| p item; end; puts
41
+ p "Item[4, 5].each do |item|"
42
+ Item[4, 5].each do |item|
43
+ p item
44
+ end
45
+ puts
46
+
47
+ p "Item[4..8].each do |item|"
48
+ Item[4..8].each do |item|
49
+ p item
50
+ end
51
+ puts
52
+
53
+ p "Item[4...8].each do |item|"
54
+ Item[4...8].each do |item|
55
+ p item
56
+ end
57
+ puts
58
+
@@ -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,17 +1,12 @@
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
 
11
6
  book = Book.new
12
7
  book.title = "title basic 1"
13
8
  book.author = "Alice"
14
- book.style = "A4"
9
+ book.size = "A4"
15
10
  book.price = 1000
16
11
  book.page = 100
17
12
  book.save
@@ -1,13 +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
-
11
- 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 )
12
7
  book.save
13
8
 
@@ -1,13 +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
-
11
- 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 }
12
7
  Book.create( **doc )
13
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,25 +8,28 @@ 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
21
21
 
22
-
23
22
  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
- book.publish_at = Date.today
31
30
  book.isbn = "978-3-16-148410-0"
32
31
  book.lang = "en"
32
+ book.created_at = Time.now
33
+ book.updated_at = Time.now
33
34
  book.save
34
35
 
@@ -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,25 +8,28 @@ 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
21
21
 
22
-
23
22
  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
- book.publish_at = Date.today
31
30
  book.isbn = "978-3-16-148410-0"
32
31
  book.lang = "en"
32
+ book.created_at = Time.now
33
+ book.updated_at = Time.now
33
34
  book.save
34
35
 
@@ -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
 
@@ -25,16 +25,17 @@ class Book
25
25
  end
26
26
  end
27
27
 
28
-
29
28
  book = Book.new
30
29
  book.title = "title detail 3"
31
30
  book.author = "Candy"
32
- #book.publisher = "Foobar"
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
- #book.publish_at = Date.today
37
36
  book.isbn = "978-3-16-148410-0"
38
- #book.lang
37
+ # book.lang
38
+ # book.created_at
39
+ # book.updated_at
39
40
  book.save
40
41
 
@@ -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, 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
- field :date, Date, &proc{ Date.today }
15
13
  field :page, Integer, proc{ page > 0 }
16
14
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
15
+ field :lang, String, 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
  verify { having?( title ) }
@@ -33,7 +33,8 @@ begin
33
33
  book = Book.new
34
34
  book.title = "title verify 1"
35
35
  book.author = "jane doe"
36
- book.style = "A5"
36
+ book.style = "softcover"
37
+ book.size = "A5"
37
38
  book.price = 2000
38
39
  book.page = 200
39
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,14 +1,12 @@
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 :page, Integer, proc{ page > 1 }
11
- field :price, Integer, proc{ (price > 0) & (price < 10_000) }
9
+ field :price, Integer, proc{ (price > 0) && (price < 10_000) }
12
10
 
13
11
  end
14
12
 
@@ -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