mongous 0.1.3 → 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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +142 -27
  3. data/README.ja.adoc +140 -25
  4. data/lib/mongous/document.rb +50 -27
  5. data/lib/mongous/extention.rb +56 -45
  6. data/lib/mongous/filter.rb +76 -57
  7. data/lib/mongous/version.rb +1 -1
  8. data/mongous.gemspec +3 -2
  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 +1 -1
  14. data/sample/declare_label_1.rb +1 -1
  15. data/sample/declare_ndex_1.rb +1 -1
  16. data/sample/declare_ndex_2.rb +1 -1
  17. data/sample/declare_strict_1.rb +7 -5
  18. data/sample/declare_strict_2.rb +3 -2
  19. data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
  20. data/sample/multi_collection_2.rb +61 -0
  21. data/sample/query_basic_1.rb +3 -1
  22. data/sample/query_basic_2.rb +5 -3
  23. data/sample/query_basic_3.rb +2 -3
  24. data/sample/query_basic_4.rb +3 -4
  25. data/sample/query_basic_5.rb +2 -3
  26. data/sample/query_detail_3.rb +3 -2
  27. data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
  28. data/sample/query_filter_2.rb +50 -0
  29. data/sample/query_find_1.rb +31 -0
  30. data/sample/query_projection_1.rb +5 -8
  31. data/sample/query_skip_limit_1.rb +37 -0
  32. data/sample/query_skip_limit_2.rb +49 -0
  33. data/sample/query_sort_order_1.rb +46 -0
  34. data/sample/save_basic_1.rb +0 -1
  35. data/sample/save_basic_2.rb +0 -1
  36. data/sample/save_basic_3.rb +0 -1
  37. data/sample/save_detail_1.rb +4 -3
  38. data/sample/save_detail_2.rb +4 -3
  39. data/sample/save_detail_3.rb +6 -5
  40. data/sample/save_verify_1.rb +3 -2
  41. data/sample/save_verify_3.rb +1 -1
  42. data/sample/zap_basic_2.rb +1 -1
  43. data/sample/zap_basic_3.rb +1 -1
  44. metadata +15 -14
  45. data/sample/multi_docs_2.rb +0 -58
  46. data/sample/query_limit_1.rb +0 -44
  47. data/sample/query_order_1.rb +0 -49
  48. data/sample/query_raw_1.rb +0 -33
  49. data/sample/template_article.rb +0 -5
  50. data/sample/template_person.rb +0 -12
@@ -0,0 +1,37 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ p count = Book.where.count
11
+ puts
12
+
13
+ p count = Book.where[0..4].count
14
+ puts
15
+
16
+ p count = Book.where[0...4].count
17
+ puts
18
+
19
+ p count = Book.where[0, 4].count
20
+ puts
21
+
22
+ p count = Book.where[5, 5].count
23
+ puts
24
+
25
+ pp books = Book.where[0, 2].all
26
+ puts
27
+
28
+ filter = Book.where( title: /title/ )
29
+ filter[0, 4].each do |book|
30
+ p book
31
+ end
32
+ puts
33
+ filter[4, 4].each do |book|
34
+ p book
35
+ end
36
+ puts
37
+
@@ -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 )
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,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.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - ARIMA Yasuhiro
7
+ - arimay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-02 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,21 +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
100
  - sample/query_detail_1.rb
102
101
  - sample/query_detail_2.rb
103
102
  - sample/query_detail_3.rb
104
- - sample/query_limit_1.rb
105
- - sample/query_order_1.rb
103
+ - sample/query_filter_1.rb
104
+ - sample/query_filter_2.rb
105
+ - sample/query_find_1.rb
106
106
  - sample/query_projection_1.rb
107
- - sample/query_raw_1.rb
107
+ - sample/query_skip_limit_1.rb
108
+ - sample/query_skip_limit_2.rb
109
+ - sample/query_sort_order_1.rb
108
110
  - sample/save_basic_1.rb
109
111
  - sample/save_basic_2.rb
110
112
  - sample/save_basic_3.rb
@@ -117,13 +119,12 @@ files:
117
119
  - sample/save_verify_4.rb
118
120
  - sample/save_verify_5.rb
119
121
  - sample/save_verify_6.rb
120
- - sample/template_article.rb
121
- - sample/template_person.rb
122
122
  - sample/zap_basic_1.rb
123
123
  - sample/zap_basic_2.rb
124
124
  - sample/zap_basic_3.rb
125
- homepage:
126
- licenses: []
125
+ homepage: https://github.com/arimay/mongous
126
+ licenses:
127
+ - MIT
127
128
  metadata: {}
128
129
  post_install_message:
129
130
  rdoc_options: []
@@ -133,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
134
  requirements:
134
135
  - - ">="
135
136
  - !ruby/object:Gem::Version
136
- version: 2.6.0
137
+ version: '0'
137
138
  required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  requirements:
139
140
  - - ">="
@@ -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,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
-