mongous 0.1.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +216 -44
  3. data/README.ja.adoc +217 -45
  4. data/lib/mongous/base.rb +30 -0
  5. data/lib/mongous/document.rb +75 -32
  6. data/lib/mongous/extention.rb +55 -46
  7. data/lib/mongous/filter.rb +82 -60
  8. data/lib/mongous/version.rb +1 -1
  9. data/sample/connect_auto_2.rb +2 -1
  10. data/sample/connect_default_2.rb +2 -1
  11. data/sample/connect_environ_2.rb +2 -1
  12. data/sample/connect_loadfile_2.rb +2 -1
  13. data/sample/declare_compact_1.rb +7 -7
  14. data/sample/declare_label_1.rb +10 -6
  15. data/sample/declare_ndex_1.rb +9 -5
  16. data/sample/declare_ndex_2.rb +10 -6
  17. data/sample/declare_strict_1.rb +14 -10
  18. data/sample/declare_strict_2.rb +5 -3
  19. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  20. data/sample/multi_collection_2.rb +63 -0
  21. data/sample/multi_collection_3.rb +26 -0
  22. data/sample/query_basic_1.rb +3 -1
  23. data/sample/query_basic_2.rb +5 -3
  24. data/sample/query_basic_3.rb +2 -3
  25. data/sample/query_basic_4.rb +3 -4
  26. data/sample/query_basic_5.rb +2 -3
  27. data/sample/query_detail_1.rb +3 -1
  28. data/sample/query_detail_2.rb +3 -1
  29. data/sample/query_detail_3.rb +5 -3
  30. data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
  31. data/sample/query_filter_2.rb +50 -0
  32. data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
  33. data/sample/query_projection_1.rb +5 -8
  34. data/sample/query_skip_limit_1.rb +47 -0
  35. data/sample/query_skip_limit_2.rb +49 -0
  36. data/sample/query_sort_order_1.rb +46 -0
  37. data/sample/save_basic_1.rb +1 -2
  38. data/sample/save_basic_2.rb +1 -2
  39. data/sample/save_basic_3.rb +1 -2
  40. data/sample/save_detail_1.rb +7 -4
  41. data/sample/save_detail_2.rb +7 -4
  42. data/sample/save_detail_3.rb +11 -8
  43. data/sample/save_verify_1.rb +7 -4
  44. data/sample/save_verify_3.rb +1 -1
  45. data/sample/save_verify_5.rb +3 -3
  46. data/sample/save_verify_6.rb +3 -3
  47. data/sample/save_verify_7.rb +23 -0
  48. data/sample/update_basic_1.rb +13 -0
  49. data/sample/zap_basic_2.rb +2 -2
  50. data/sample/zap_basic_3.rb +2 -2
  51. data/sample/zbenchmark_search_1.rb +110 -0
  52. data/sample/zbenchmark_search_2.rb +110 -0
  53. metadata +15 -10
  54. data/sample/multi_docs_2.rb +0 -58
  55. data/sample/query_limit_1.rb +0 -44
  56. data/sample/query_order_1.rb +0 -49
  57. data/sample/template_article.rb +0 -5
  58. data/sample/template_person.rb +0 -12
@@ -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,12 +7,15 @@ 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/ )
15
- filter2 = Book.not( author: /Candy/ )
17
+ filter1 = Book.where( title: /comp/ )
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 )
18
21
  p filter1.to_condition
@@ -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
 
@@ -7,11 +7,8 @@ class Label
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  (0...10).each do |n|
12
- if label = Label.filter( n: n ).first
13
- label
14
- else
11
+ unless Label.where( n: n ).first
15
12
  Label.create( n: n, tag: [0x40 + n].pack("C") )
16
13
  end
17
14
  end
@@ -22,22 +19,22 @@ Label.each do |label|
22
19
  end
23
20
  puts
24
21
 
25
- Label.filter.projection( tag: 1 ).each do |label|
22
+ Label.where.projection( tag: 1 ).each do |label|
26
23
  p label
27
24
  end
28
25
  puts
29
26
 
30
- Label.filter.projection( _id: 0, n: 1 ).each do |label|
27
+ Label.where.projection( _id: 0, n: 1 ).each do |label|
31
28
  p label
32
29
  end
33
30
  puts
34
31
 
35
- Label.filter.select( _id: 0, n: 1, tag: 1 ).each do |label|
32
+ Label.where.select( _id: 0, n: 1, tag: 1 ).each do |label|
36
33
  p label
37
34
  end
38
35
  puts
39
36
 
40
- Label.filter( n: [0,2,4,6,8] ).select( _id: 0, n: 1, tag: 1 ).each do |label|
37
+ Label.where( n: [0,2,4,6,8] ).select( _id: 0, n: 1, tag: 1 ).each do |label|
41
38
  p label
42
39
  end
43
40
  puts
@@ -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
 
@@ -9,12 +9,14 @@ class Book
9
9
  field :title, String, :must
10
10
  field :author, String
11
11
  field :publisher, String
12
- field :style, String, ["A4","A5","A6"]
12
+ field :style, String, %w[hardcover softcover paperback]
13
+ field :size, String, /[AB]\d/
13
14
  field :price, Integer, (0..1_000_000)
14
- field :date, Date, &proc{ Date.today }
15
15
  field :page, Integer, proc{ page > 0 }
16
16
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
17
+ field :lang, String, 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
  verify { having?( title ) }
@@ -33,7 +35,8 @@ begin
33
35
  book = Book.new
34
36
  book.title = "title verify 1"
35
37
  book.author = "jane doe"
36
- book.style = "A5"
38
+ book.style = "softcover"
39
+ book.size = "A5"
37
40
  book.price = 2000
38
41
  book.page = 200
39
42
  book.isbn = "978-3-16-148410-0"