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,13 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Book
7
+ include Mongous::Document
8
+ end
9
+
10
+ Book.where( title: /title/ ).each do |book|
11
+ book.price = (book.price || 50 ) * 2
12
+ book.save
13
+ end
@@ -3,9 +3,9 @@ require "mongous"
3
3
 
4
4
  Mongous.connect!
5
5
 
6
- class Book
6
+ class Item
7
7
  include Mongous::Document
8
8
  end
9
9
 
10
- Book.filter( title: "title 1" ).delete
10
+ Item.where.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.4
4
+ version: 0.2.1
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-02 00:00:00.000000000 Z
11
+ date: 2020-10-08 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,11 +119,10 @@ 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
+ - sample/save_verify_7.rb
123
+ - sample/update_basic_1.rb
122
124
  - sample/zap_basic_1.rb
123
125
  - sample/zap_basic_2.rb
124
- - sample/zap_basic_3.rb
125
126
  homepage: https://github.com/arimay/mongous
126
127
  licenses:
127
128
  - MIT
@@ -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
-
@@ -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
-
@@ -1,33 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
-
11
- book = Book.collection.find.first
12
- p book
13
- puts
14
-
15
- Book.collection.find.each do |book|
16
- p book
17
- end
18
- puts
19
-
20
- Book.collection.find( title: /title/ ).each do |book|
21
- p book
22
- end
23
- puts
24
-
25
- Book.collection.find( {}, { projection: {_id: 0, title: 1, author: 1} } ).each do |book|
26
- p book
27
- end
28
- puts
29
-
30
- Book.collection.find( {title: /title/}, { projection: {_id: 0, title: 1, author: 1} } ).each do |book|
31
- p book
32
- end
33
-
@@ -1,5 +0,0 @@
1
-
2
- class Article
3
- include Mongous::Document
4
- end
5
-
@@ -1,12 +0,0 @@
1
-
2
- class Person
3
- include Mongous::Document
4
-
5
- field :fullname
6
- field :username
7
- field :age, Integer
8
- field :created_at, Date, &proc{ Date.today }
9
-
10
- verify :strict
11
- end
12
-
@@ -1,11 +0,0 @@
1
-
2
- require "mongous"
3
-
4
- Mongous.connect!
5
-
6
- class Book
7
- include Mongous::Document
8
- end
9
-
10
- Book.filter( title: /title/ ).delete
11
-