mongous 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +142 -27
- data/README.ja.adoc +140 -25
- data/lib/mongous/document.rb +50 -27
- data/lib/mongous/extention.rb +56 -45
- data/lib/mongous/filter.rb +76 -57
- data/lib/mongous/version.rb +1 -1
- data/mongous.gemspec +3 -2
- data/sample/connect_auto_2.rb +2 -1
- data/sample/connect_default_2.rb +2 -1
- data/sample/connect_environ_2.rb +2 -1
- data/sample/connect_loadfile_2.rb +2 -1
- data/sample/declare_compact_1.rb +1 -1
- data/sample/declare_label_1.rb +1 -1
- data/sample/declare_ndex_1.rb +1 -1
- data/sample/declare_ndex_2.rb +1 -1
- data/sample/declare_strict_1.rb +7 -5
- data/sample/declare_strict_2.rb +3 -2
- data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
- data/sample/multi_collection_2.rb +61 -0
- data/sample/query_basic_1.rb +3 -1
- data/sample/query_basic_2.rb +5 -3
- data/sample/query_basic_3.rb +2 -3
- data/sample/query_basic_4.rb +3 -4
- data/sample/query_basic_5.rb +2 -3
- data/sample/query_detail_3.rb +3 -2
- data/sample/{query_basic_6.rb → query_filter_1.rb} +8 -5
- data/sample/query_filter_2.rb +50 -0
- data/sample/query_find_1.rb +31 -0
- data/sample/query_projection_1.rb +5 -8
- data/sample/query_skip_limit_1.rb +37 -0
- data/sample/query_skip_limit_2.rb +49 -0
- data/sample/query_sort_order_1.rb +46 -0
- data/sample/save_basic_1.rb +0 -1
- data/sample/save_basic_2.rb +0 -1
- data/sample/save_basic_3.rb +0 -1
- data/sample/save_detail_1.rb +4 -3
- data/sample/save_detail_2.rb +4 -3
- data/sample/save_detail_3.rb +6 -5
- data/sample/save_verify_1.rb +3 -2
- data/sample/save_verify_3.rb +1 -1
- data/sample/zap_basic_2.rb +1 -1
- data/sample/zap_basic_3.rb +1 -1
- metadata +15 -14
- data/sample/multi_docs_2.rb +0 -58
- data/sample/query_limit_1.rb +0 -44
- data/sample/query_order_1.rb +0 -49
- data/sample/query_raw_1.rb +0 -33
- data/sample/template_article.rb +0 -5
- 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
|
+
|
data/sample/save_basic_1.rb
CHANGED
data/sample/save_basic_2.rb
CHANGED
data/sample/save_basic_3.rb
CHANGED
data/sample/save_detail_1.rb
CHANGED
@@ -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
|
|
data/sample/save_detail_2.rb
CHANGED
@@ -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
|
|
data/sample/save_detail_3.rb
CHANGED
@@ -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,
|
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
|
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
|
|
data/sample/save_verify_1.rb
CHANGED
@@ -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,
|
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 ) }
|
data/sample/save_verify_3.rb
CHANGED
data/sample/zap_basic_2.rb
CHANGED
data/sample/zap_basic_3.rb
CHANGED
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.
|
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-
|
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/
|
94
|
-
- sample/
|
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/
|
105
|
-
- sample/
|
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/
|
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:
|
137
|
+
version: '0'
|
137
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
139
|
requirements:
|
139
140
|
- - ">="
|
data/sample/multi_docs_2.rb
DELETED
@@ -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
|
-
|
data/sample/query_limit_1.rb
DELETED
@@ -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
|
-
|