mongous 0.1.8 → 0.2.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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +115 -30
  3. data/README.ja.adoc +115 -30
  4. data/lib/mongous/document.rb +50 -27
  5. data/lib/mongous/extention.rb +50 -43
  6. data/lib/mongous/filter.rb +45 -51
  7. data/lib/mongous/version.rb +1 -1
  8. data/sample/declare_compact_1.rb +1 -1
  9. data/sample/declare_label_1.rb +1 -1
  10. data/sample/declare_ndex_1.rb +1 -1
  11. data/sample/declare_ndex_2.rb +1 -1
  12. data/sample/declare_strict_1.rb +7 -5
  13. data/sample/declare_strict_2.rb +3 -2
  14. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  15. data/sample/multi_collection_2.rb +61 -0
  16. data/sample/query_basic_1.rb +0 -1
  17. data/sample/query_basic_2.rb +4 -5
  18. data/sample/query_basic_3.rb +2 -3
  19. data/sample/query_basic_4.rb +3 -4
  20. data/sample/query_basic_5.rb +2 -3
  21. data/sample/query_detail_3.rb +3 -2
  22. data/sample/{query_basic_6.rb → query_filter_1.rb} +7 -4
  23. data/sample/query_filter_2.rb +50 -0
  24. data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
  25. data/sample/query_projection_1.rb +5 -8
  26. data/sample/query_skip_limit_1.rb +37 -0
  27. data/sample/query_skip_limit_2.rb +49 -0
  28. data/sample/query_sort_order_1.rb +46 -0
  29. data/sample/save_basic_1.rb +0 -1
  30. data/sample/save_basic_2.rb +0 -1
  31. data/sample/save_basic_3.rb +0 -1
  32. data/sample/save_detail_1.rb +4 -3
  33. data/sample/save_detail_2.rb +4 -3
  34. data/sample/save_detail_3.rb +6 -5
  35. data/sample/save_verify_1.rb +3 -2
  36. data/sample/save_verify_3.rb +1 -1
  37. data/sample/zap_basic_2.rb +1 -1
  38. data/sample/zap_basic_3.rb +1 -1
  39. metadata +10 -11
  40. data/sample/multi_docs_2.rb +0 -58
  41. data/sample/query_basic_7.rb +0 -38
  42. data/sample/query_limit_1.rb +0 -44
  43. data/sample/query_order_1.rb +0 -49
  44. data/sample/template_article.rb +0 -5
  45. data/sample/template_person.rb +0 -12
@@ -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,7 +7,6 @@ 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"
@@ -7,7 +7,6 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
-
11
10
  book = Book.new( title: "title basic 2", author: "Bob", style: "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
10
  doc = { title: "title basic 3", author: "Candy", style: "A6", price: 3000, page: 300 }
12
11
  Book.create( **doc )
13
12
 
@@ -12,14 +12,14 @@ class Book
12
12
  field :style
13
13
  field :price
14
14
  field :page
15
- field :publish_at
16
15
  field :isbn
17
16
  field :lang
17
+ field :created_at
18
+ field :updated_at
18
19
 
19
20
  verify :strict
20
21
  end
21
22
 
22
-
23
23
  book = Book.new
24
24
  book.title = "title detail 1"
25
25
  book.author = "Alice"
@@ -27,8 +27,9 @@ book.publisher = "Foobar"
27
27
  book.style = "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
 
@@ -12,14 +12,14 @@ class Book
12
12
  field :style
13
13
  field :price, Integer
14
14
  field :page, Integer
15
- field :publish_at, Date
16
15
  field :isbn
17
16
  field :lang
17
+ field :created_at, Time
18
+ field :updated_at, Time
18
19
 
19
20
  verify :strict
20
21
  end
21
22
 
22
-
23
23
  book = Book.new
24
24
  book.title = "title detail 2"
25
25
  book.author = "Bob"
@@ -27,8 +27,9 @@ book.publisher = "Foobar"
27
27
  book.style = "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
 
@@ -12,9 +12,10 @@ class Book
12
12
  field :style, %w[ A4 A5 A6 ]
13
13
  field :price, Integer, (0..1_000_000)
14
14
  field :page, Integer, proc{ page > 0 }
15
- field :publish_at, Date, &proc{ Date.today }
16
15
  field :isbn, proc{ isbn? }
17
- field :lang, &proc{ "ja" }
16
+ field :lang, default: "en"
17
+ field :created_at, Time, create: ->(){ Time.now }
18
+ field :updated_at, Time, update: ->(){ Time.now }
18
19
 
19
20
  verify :strict
20
21
 
@@ -25,16 +26,16 @@ class Book
25
26
  end
26
27
  end
27
28
 
28
-
29
29
  book = Book.new
30
30
  book.title = "title detail 3"
31
31
  book.author = "Candy"
32
- #book.publisher = "Foobar"
32
+ #book.publisher
33
33
  book.style = "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
37
  #book.lang
38
+ #book.created_at
39
+ #book.updated_at
39
40
  book.save
40
41
 
@@ -11,10 +11,11 @@ class Book
11
11
  field :publisher, String
12
12
  field :style, String, ["A4","A5","A6"]
13
13
  field :price, Integer, (0..1_000_000)
14
- field :date, Date, &proc{ Date.today }
15
14
  field :page, Integer, proc{ page > 0 }
16
15
  field :isbn, String, proc{ isbn? }
17
- field :lang, String, &proc{ "ja" }
16
+ field :lang, String, default: "en"
17
+ field :created_at, Time, create: ->(){ Time.now }
18
+ field :updated_at, Time, update: ->(){ Time.now }
18
19
 
19
20
  verify :strict
20
21
  verify { having?( title ) }
@@ -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,5 +7,5 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.filter( title: "title 1" ).delete
10
+ Book.where( title: "title 1" ).delete
11
11
 
@@ -7,5 +7,5 @@ class Book
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.filter( title: /title/ ).delete
10
+ Book.where( title: /title/ ).delete
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arimay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-05 00:00:00.000000000 Z
11
+ date: 2020-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -90,22 +90,23 @@ files:
90
90
  - sample/declare_ndex_2.rb
91
91
  - sample/declare_strict_1.rb
92
92
  - sample/declare_strict_2.rb
93
- - sample/multi_docs_1.rb
94
- - sample/multi_docs_2.rb
93
+ - sample/multi_collection_1.rb
94
+ - sample/multi_collection_2.rb
95
95
  - sample/query_basic_1.rb
96
96
  - sample/query_basic_2.rb
97
97
  - sample/query_basic_3.rb
98
98
  - sample/query_basic_4.rb
99
99
  - sample/query_basic_5.rb
100
- - sample/query_basic_6.rb
101
- - sample/query_basic_7.rb
102
100
  - sample/query_detail_1.rb
103
101
  - sample/query_detail_2.rb
104
102
  - sample/query_detail_3.rb
105
- - sample/query_limit_1.rb
106
- - sample/query_order_1.rb
103
+ - sample/query_filter_1.rb
104
+ - sample/query_filter_2.rb
105
+ - sample/query_find_1.rb
107
106
  - sample/query_projection_1.rb
108
- - sample/query_super_1.rb
107
+ - sample/query_skip_limit_1.rb
108
+ - sample/query_skip_limit_2.rb
109
+ - sample/query_sort_order_1.rb
109
110
  - sample/save_basic_1.rb
110
111
  - sample/save_basic_2.rb
111
112
  - sample/save_basic_3.rb
@@ -118,8 +119,6 @@ files:
118
119
  - sample/save_verify_4.rb
119
120
  - sample/save_verify_5.rb
120
121
  - sample/save_verify_6.rb
121
- - sample/template_article.rb
122
- - sample/template_person.rb
123
122
  - sample/zap_basic_1.rb
124
123
  - sample/zap_basic_2.rb
125
124
  - sample/zap_basic_3.rb
@@ -1,58 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book1
7
- include Mongous::Document
8
- end
9
-
10
- class Book2
11
- include Mongous::Document
12
-
13
- field :title
14
- field :publisher
15
- field :author
16
- field :style
17
- field :price
18
- field :page
19
- field :publish_at
20
- field :isbn
21
- field :lang
22
-
23
- verify :strict
24
- end
25
-
26
- class Book3
27
- include Mongous::Document
28
-
29
- field :title, :must
30
- field :author,
31
- field :publisher,
32
- field :price, Integer, (0..1_000_000)
33
- field :page, Integer, proc{ page > 0 }
34
- field :publish_at, Date, &proc{ Date.today }
35
- field :isbn, proc{ isbn? }
36
- field :lang, &proc{ "ja" }
37
-
38
- verify :strict
39
- verify { having?( title ) }
40
- verify do
41
- having?( author ) | having?( publisher )
42
- end
43
-
44
- def isbn?
45
- isbn&.gsub(/[\D]*/, '').size == 13
46
- end
47
- end
48
-
49
-
50
- pp Book1.fields
51
- puts
52
-
53
- pp Book2.fields
54
- puts
55
-
56
- pp Book3.fields
57
- puts
58
-
@@ -1,38 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
-
11
- p count = Book.filter.count
12
- puts
13
-
14
- p count = Book.filter[0..4].count
15
- puts
16
-
17
- p count = Book.filter[0...4].count
18
- puts
19
-
20
- p count = Book.filter[0, 4].count
21
- puts
22
-
23
- p count = Book.filter[20,10].count
24
- puts
25
-
26
- pp books = Book.filter[0, 2].all
27
- puts
28
-
29
- filter = Book.filter( title: /title/ )
30
- filter[0, 4].each do |book|
31
- p book
32
- end
33
- puts
34
- filter[4, 4].each do |book|
35
- p book
36
- end
37
- puts
38
-
@@ -1,44 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Item
7
- include Mongous::Document
8
- end
9
-
10
-
11
- (0...10).each do |n|
12
- if item = Item.filter( n: n ).first
13
- item
14
- else
15
- Item.create( n: n )
16
- end
17
- end
18
- puts
19
-
20
- Item.each do |item|
21
- p item
22
- end
23
- puts
24
-
25
- Item.filter.skip(2).each do |item|
26
- p item
27
- end
28
- puts
29
-
30
- Item.filter.limit(3).each do |item|
31
- p item
32
- end
33
- puts
34
-
35
- Item.filter.skip(4).limit(5).each do |item|
36
- p item
37
- end
38
- puts
39
-
40
- Item.filter.offset(4).limit(5).each do |item|
41
- p item
42
- end
43
- puts
44
-
@@ -1,49 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Item
7
- include Mongous::Document
8
- end
9
-
10
-
11
- (0...10).each do |n|
12
- if item = Item.filter( n: n ).first
13
- item
14
- else
15
- Item.create( n: n )
16
- end
17
- end
18
- puts
19
-
20
- Item.each do |item|
21
- p item
22
- end
23
- puts
24
-
25
- Item.filter.sort(n: 1).each do |item|
26
- p item
27
- end
28
- puts
29
-
30
- Item.filter.sort(n: -1).each do |item|
31
- p item
32
- end
33
- puts
34
-
35
- Item.filter.order(n: -1).each do |item|
36
- p item
37
- end
38
- puts
39
-
40
- Item.filter( n: (3...8) ).order(n: -1).each do |item|
41
- p item
42
- end
43
- puts
44
-
45
- Item.filter( n: [0,2,4,6,8] ).order(n: -1).each do |item|
46
- p item
47
- end
48
- puts
49
-