mongous 0.1.4 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +156 -37
  3. data/README.ja.adoc +155 -36
  4. data/lib/mongous/document.rb +66 -31
  5. data/lib/mongous/extention.rb +59 -46
  6. data/lib/mongous/filter.rb +82 -60
  7. data/lib/mongous/version.rb +1 -1
  8. data/sample/connect_auto_2.rb +2 -1
  9. data/sample/connect_default_2.rb +2 -1
  10. data/sample/connect_environ_2.rb +2 -1
  11. data/sample/connect_loadfile_2.rb +2 -1
  12. data/sample/declare_compact_1.rb +4 -3
  13. data/sample/declare_label_1.rb +5 -3
  14. data/sample/declare_ndex_1.rb +5 -3
  15. data/sample/declare_ndex_2.rb +5 -3
  16. data/sample/declare_strict_1.rb +14 -10
  17. data/sample/declare_strict_2.rb +5 -3
  18. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  19. data/sample/multi_collection_2.rb +63 -0
  20. data/sample/query_basic_1.rb +3 -1
  21. data/sample/query_basic_2.rb +5 -3
  22. data/sample/query_basic_3.rb +2 -3
  23. data/sample/query_basic_4.rb +3 -4
  24. data/sample/query_basic_5.rb +2 -3
  25. data/sample/query_detail_1.rb +1 -0
  26. data/sample/query_detail_2.rb +1 -0
  27. data/sample/query_detail_3.rb +5 -3
  28. data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
  29. data/sample/query_filter_2.rb +50 -0
  30. data/sample/query_find_1.rb +31 -0
  31. data/sample/query_projection_1.rb +5 -8
  32. data/sample/query_skip_limit_1.rb +47 -0
  33. data/sample/query_skip_limit_2.rb +49 -0
  34. data/sample/query_sort_order_1.rb +46 -0
  35. data/sample/save_basic_1.rb +1 -2
  36. data/sample/save_basic_2.rb +1 -2
  37. data/sample/save_basic_3.rb +1 -2
  38. data/sample/save_detail_1.rb +7 -4
  39. data/sample/save_detail_2.rb +7 -4
  40. data/sample/save_detail_3.rb +10 -7
  41. data/sample/save_verify_1.rb +7 -4
  42. data/sample/save_verify_3.rb +1 -1
  43. data/sample/save_verify_5.rb +3 -3
  44. data/sample/save_verify_6.rb +3 -3
  45. data/sample/save_verify_7.rb +23 -0
  46. data/sample/update_basic_1.rb +13 -0
  47. data/sample/zap_basic_2.rb +2 -2
  48. metadata +12 -11
  49. data/sample/multi_docs_2.rb +0 -58
  50. data/sample/query_limit_1.rb +0 -44
  51. data/sample/query_order_1.rb +0 -49
  52. data/sample/query_raw_1.rb +0 -33
  53. data/sample/template_article.rb +0 -5
  54. data/sample/template_person.rb +0 -12
  55. data/sample/zap_basic_3.rb +0 -11
@@ -0,0 +1,31 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ p book = Book.find.first
11
+ puts
12
+
13
+ Book.find.each do |book|
14
+ p book
15
+ end
16
+ puts
17
+
18
+ Book.find( title: /title/ ).each do |book|
19
+ p book
20
+ end
21
+ puts
22
+
23
+ Book.find( {}, { projection: {_id: 0} } ).each do |book|
24
+ p book
25
+ end
26
+ puts
27
+
28
+ Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
29
+ p book
30
+ end
31
+
@@ -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
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: ->(){ Time.now }
19
+ field :updated_at, Time, update: ->(){ 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"
@@ -8,7 +8,7 @@ class Book
8
8
 
9
9
  field :title, :must
10
10
  field :page, Integer, proc{ page > 1 }
11
- field :price, Integer, proc{ (price > 0) & (price < 10_000) }
11
+ field :price, Integer, proc{ (price > 0) && (price < 10_000) }
12
12
 
13
13
  end
14
14
 
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :style, String, ["A4","A5","A6"]
10
+ field :size, String, /[AB]\d/
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title isbn"
16
- book.style = "B5"
15
+ book.title = "title size"
16
+ book.size = "C5"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -7,13 +7,13 @@ class Book
7
7
  include Mongous::Document
8
8
 
9
9
  field :title, :must
10
- field :price, Integer, (0..1_000_000)
10
+ field :style, String, %w[hardcover softcover paperback]
11
11
  end
12
12
 
13
13
  begin
14
14
  book = Book.new
15
- book.title = "title price"
16
- book.price = -1
15
+ book.title = "title style"
16
+ book.style = "newspaper"
17
17
  book.save
18
18
 
19
19
  rescue => e
@@ -0,0 +1,23 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+
9
+ field :title, :must
10
+ field :price, Integer, (0..1_000_000)
11
+ end
12
+
13
+ begin
14
+ book = Book.new
15
+ book.title = "title price"
16
+ book.price = -1
17
+ book.save
18
+
19
+ rescue => e
20
+ p e.message
21
+
22
+ end
23
+