mongous 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.adoc +19 -15
- data/README.ja.adoc +20 -16
- data/lib/mongous/document.rb +17 -5
- data/lib/mongous/extention.rb +6 -4
- data/lib/mongous/filter.rb +8 -5
- data/lib/mongous/version.rb +1 -1
- data/sample/declare_compact_1.rb +3 -2
- data/sample/declare_label_1.rb +4 -2
- data/sample/declare_ndex_1.rb +4 -2
- data/sample/declare_ndex_2.rb +4 -2
- data/sample/declare_strict_1.rb +9 -7
- data/sample/declare_strict_2.rb +4 -3
- data/sample/multi_collection_2.rb +5 -3
- data/sample/query_basic_4.rb +3 -3
- data/sample/query_detail_1.rb +1 -0
- data/sample/query_detail_2.rb +1 -0
- data/sample/query_detail_3.rb +4 -3
- data/sample/query_filter_1.rb +1 -1
- data/sample/query_filter_2.rb +2 -2
- data/sample/query_skip_limit_1.rb +22 -12
- data/sample/query_skip_limit_2.rb +1 -1
- data/sample/save_basic_1.rb +1 -1
- data/sample/save_basic_2.rb +1 -1
- data/sample/save_basic_3.rb +1 -1
- data/sample/save_detail_1.rb +3 -1
- data/sample/save_detail_2.rb +3 -1
- data/sample/save_detail_3.rb +6 -4
- data/sample/save_verify_1.rb +4 -2
- data/sample/save_verify_5.rb +3 -3
- data/sample/save_verify_6.rb +3 -3
- data/sample/save_verify_7.rb +23 -0
- data/sample/update_basic_1.rb +13 -0
- data/sample/zap_basic_2.rb +2 -2
- metadata +4 -3
- data/sample/zap_basic_3.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dded44fdc39ecb6ff4eeb6db10183e3a940f19317062a73d85ecf4d4c6e10437
|
4
|
+
data.tar.gz: 34fa872a88fdc0aac33101465a490fb71f9132542e7f4583f86313527c532d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b39238447cf6419f663b22563930a5e32671983e29395bfc31dabeaf77d1dfca3ff7dbd84e54b8e231c9f8810729c2701d491b7ae9e3e8171eda400a97bf041
|
7
|
+
data.tar.gz: 7660804d5e3452714dbcbe0ac30a532789dbc553f3e5929ec58d4f0dfafd4bb9bd4dc0cb8aa124265c9af6dd6ac25acfc1361b4fa239317fc2a5bde26eb2e932
|
data/README.adoc
CHANGED
@@ -5,9 +5,12 @@ Yet another mongo wrapper library.
|
|
5
5
|
== Features
|
6
6
|
|
7
7
|
* A light library that depends only on the mongo driver and bson, except for built-in and standard attachments.
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
8
|
+
* Document item constraints can be described in Array, Range, Regexp, Proc instances, or base classes.
|
9
|
+
* Check if the constraint conditions are met when saving the document.
|
10
|
+
* Check if the constraint condition is satisfied when setting the item value of the document.
|
11
|
+
* The contents of undefined items in the document can be described by value or Proc.
|
12
|
+
* Item settings can be described in values or Proc when creating a document.
|
13
|
+
* Item settings can be described in values or Proc when updating the document.
|
11
14
|
|
12
15
|
== Installation
|
13
16
|
|
@@ -57,13 +60,14 @@ class Book
|
|
57
60
|
field :title, String, :must
|
58
61
|
field :author, String
|
59
62
|
field :publisher, String
|
60
|
-
field :style, String,
|
61
|
-
field :
|
62
|
-
field :
|
63
|
-
field :
|
64
|
-
field :
|
65
|
-
field :
|
66
|
-
field :
|
63
|
+
field :style, String, %w[hardcover, softcover, paperback]
|
64
|
+
field :size, String, /[AB]\d/
|
65
|
+
field :price, Integer, (0..1_000_000)
|
66
|
+
field :page, Integer, proc{ page % 4 == 0 }
|
67
|
+
field :isbn, String, proc{ isbn? }
|
68
|
+
field :lang, String, default: "en"
|
69
|
+
field :created_at, Time, create: proc{ Time.now }
|
70
|
+
field :updated_at, Time, update: proc{ Time.now }
|
67
71
|
|
68
72
|
filter :foobar, {title: /foobar/}
|
69
73
|
|
@@ -87,13 +91,13 @@ end
|
|
87
91
|
book = Book.new
|
88
92
|
book.title = "title 1"
|
89
93
|
book.price = 1000
|
90
|
-
book.
|
94
|
+
book.size = "A4"
|
91
95
|
book.save
|
92
96
|
|
93
|
-
book = Book.new( title: "title 2", price: 2000,
|
97
|
+
book = Book.new( title: "title 2", price: 2000, size: "A5" )
|
94
98
|
book.save
|
95
99
|
|
96
|
-
doc = { title: "title 3", price: 3000,
|
100
|
+
doc = { title: "title 3", price: 3000, size: "A6" }
|
97
101
|
Book.create( **doc )
|
98
102
|
----
|
99
103
|
|
@@ -114,14 +118,14 @@ Book.where( title: /title/ ).projection( _id: 0 ).each do |book|
|
|
114
118
|
p book
|
115
119
|
end
|
116
120
|
|
117
|
-
Book.where( price: (1..2000),
|
121
|
+
Book.where( price: (1..2000), size: ["A4","A5"] ).each do |book|
|
118
122
|
p book
|
119
123
|
end
|
120
124
|
|
121
125
|
filter1 = Book.where( title: /title/ )
|
122
126
|
filter2 = Book.where( :foobar )
|
123
127
|
filter3 = Book.where( price: (1..2000) )
|
124
|
-
filter4 = Book.where(
|
128
|
+
filter4 = Book.where( size: ["A4","A5"] )
|
125
129
|
|
126
130
|
Book.not( filter1 ).each do |book|
|
127
131
|
p book
|
data/README.ja.adoc
CHANGED
@@ -5,9 +5,12 @@
|
|
5
5
|
== 特徴
|
6
6
|
|
7
7
|
* 組込みと標準添付を除いて、mongo driver と bson のみに依存する軽いライブラリである。
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
8
|
+
* ドキュメント項目の制約条件を Array, Range, Regexp, Proc インスタンスまたは基本クラスで記述できる.
|
9
|
+
* ドキュメント保存時に制約条件を満たすか検査する.
|
10
|
+
* ドキュメントの項目値設定時に制約条件を満たすか検査する.
|
11
|
+
* ドキュメントの未定義項目の内容を値または Proc で記述できる.
|
12
|
+
* ドキュメントの作成時に項目設定内容を値または Proc で記述できる.
|
13
|
+
* ドキュメントの更新時に項目設定内容を値または Proc で記述できる.
|
11
14
|
|
12
15
|
== 導入
|
13
16
|
|
@@ -54,16 +57,17 @@ Mongous.connect! ["localhost:27017"], database: "test"
|
|
54
57
|
class Book
|
55
58
|
include Mongous::Document
|
56
59
|
|
57
|
-
field :title, String,
|
60
|
+
field :title, String, :must
|
58
61
|
field :author, String
|
59
62
|
field :publisher, String
|
60
|
-
field :style, String,
|
61
|
-
field :
|
62
|
-
field :
|
63
|
-
field :
|
64
|
-
field :
|
65
|
-
field :
|
66
|
-
field :
|
63
|
+
field :style, String, %w[hardcover, softcover, paperback]
|
64
|
+
field :size, String, /[AB]\d/
|
65
|
+
field :price, Integer, (0..1_000_000)
|
66
|
+
field :page, Integer, proc{ page % 4 == 0 }
|
67
|
+
field :isbn, String, proc{ isbn? }
|
68
|
+
field :lang, String, default: "en"
|
69
|
+
field :created_at, Time, create: proc{ Time.now }
|
70
|
+
field :updated_at, Time, update: proc{ Time.now }
|
67
71
|
|
68
72
|
filter :foobar, {title: /foobar/}
|
69
73
|
|
@@ -87,13 +91,13 @@ end
|
|
87
91
|
book = Book.new
|
88
92
|
book.title = "title 1"
|
89
93
|
book.price = 1000
|
90
|
-
book.
|
94
|
+
book.size = "A4"
|
91
95
|
book.save
|
92
96
|
|
93
|
-
book = Book.new( title: "title 2", price: 2000,
|
97
|
+
book = Book.new( title: "title 2", price: 2000, size: "A5" )
|
94
98
|
book.save
|
95
99
|
|
96
|
-
doc = { title: "title 3", price: 3000,
|
100
|
+
doc = { title: "title 3", price: 3000, size: "A6" }
|
97
101
|
Book.create( **doc )
|
98
102
|
----
|
99
103
|
|
@@ -114,14 +118,14 @@ Book.where( title: /title/ ).projection( _id: 0 ).each do |book|
|
|
114
118
|
p book
|
115
119
|
end
|
116
120
|
|
117
|
-
Book.where( price: (1..2000),
|
121
|
+
Book.where( price: (1..2000), size: ["A4","A5"] ).each do |book|
|
118
122
|
p book
|
119
123
|
end
|
120
124
|
|
121
125
|
filter1 = Book.where( title: /title/ )
|
122
126
|
filter2 = Book.where( :foobar )
|
123
127
|
filter3 = Book.where( price: (1..2000) )
|
124
|
-
filter4 = Book.where(
|
128
|
+
filter4 = Book.where( size: ["A4","A5"] )
|
125
129
|
|
126
130
|
Book.not( filter1 ).each do |book|
|
127
131
|
p book
|
data/lib/mongous/document.rb
CHANGED
@@ -52,17 +52,25 @@ module Mongous
|
|
52
52
|
else
|
53
53
|
savemode = :update
|
54
54
|
end
|
55
|
+
|
55
56
|
self.class.fields.each do |label, field|
|
57
|
+
default_value = getvalue_or_callproc( field[:default] )
|
56
58
|
_must = field[:_attrs].include?(:must)
|
57
59
|
if @doc.has_key?(label)
|
58
|
-
if
|
59
|
-
|
60
|
+
if !having?( @doc[label] )
|
61
|
+
if default_value
|
62
|
+
self[label] = default_value
|
63
|
+
elsif _must
|
64
|
+
raise Mongous::Error, "must but unassigned field. : #{ label }"
|
65
|
+
elsif self.class.symbols[:strict]
|
66
|
+
self[label] = nil
|
67
|
+
end
|
60
68
|
end
|
61
69
|
else
|
62
|
-
if default_value
|
70
|
+
if default_value
|
63
71
|
self[label] = default_value
|
64
72
|
elsif _must
|
65
|
-
raise Mongous::Error, "must
|
73
|
+
raise Mongous::Error, "must but unassigned field. : #{ label }"
|
66
74
|
elsif self.class.symbols[:strict]
|
67
75
|
self[label] = nil
|
68
76
|
end
|
@@ -100,7 +108,7 @@ module Mongous
|
|
100
108
|
label = label.to_s
|
101
109
|
|
102
110
|
if self.class.symbols[:strict]
|
103
|
-
if !self.class.fields.keys.include?(label)
|
111
|
+
if !(self.class.fields.keys.include?(label) || (label == "_id"))
|
104
112
|
raise Mongous::Error, "undefined field. : #{ label }"
|
105
113
|
end
|
106
114
|
end
|
@@ -175,6 +183,10 @@ module Mongous
|
|
175
183
|
if !attr.cover?( value )
|
176
184
|
raise Mongous::Error, "out of range. : #{ label } : #{ value }"
|
177
185
|
end
|
186
|
+
when Regexp
|
187
|
+
if !attr.match( value )
|
188
|
+
raise Mongous::Error, "unmatch regexp. : #{ label } : #{ value }"
|
189
|
+
end
|
178
190
|
end
|
179
191
|
end
|
180
192
|
end
|
data/lib/mongous/extention.rb
CHANGED
@@ -105,8 +105,8 @@ module Mongous
|
|
105
105
|
|
106
106
|
attrs.each do |attr|
|
107
107
|
if klass = attr.class
|
108
|
-
if ![Class, Range, Array, Proc, Symbol].include?(klass)
|
109
|
-
raise Mongous::Error, "field
|
108
|
+
if ![Class, Range, Array, Regexp, Proc, Symbol].include?(klass)
|
109
|
+
raise Mongous::Error, "'field' arguments error. : #{ attr } on #{ symbol } at #{ call_from }"
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -114,7 +114,7 @@ module Mongous
|
|
114
114
|
items.each do |key, value|
|
115
115
|
next if [:default, :create, :update].include?(key) && [Proc, String, Numeric].include?(value.class)
|
116
116
|
|
117
|
-
raise Mongous::Error, "field
|
117
|
+
raise Mongous::Error, "'field' options error. : #{key} on #{ symbol } at #{ call_from }"
|
118
118
|
end
|
119
119
|
|
120
120
|
items[:_attrs] = attrs
|
@@ -130,6 +130,8 @@ module Mongous
|
|
130
130
|
m = /(.*?):(\d+)/.match( caller()[0] )
|
131
131
|
call_from = [ m[1], m[2] ].join(":")
|
132
132
|
blocks[call_from] = block
|
133
|
+
else
|
134
|
+
raise Mongous::Error, "'verify' arguments error. need directives or block."
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
@@ -151,7 +153,7 @@ module Mongous
|
|
151
153
|
else
|
152
154
|
m = /(.*?):(\d+)/.match( caller()[0] )
|
153
155
|
call_from = [ m[1], m[2] ].join(":")
|
154
|
-
raise Mongous::Error, "filter error. : #{symbol}, #{filter_or_condition} at #{ call_from }"
|
156
|
+
raise Mongous::Error, "'filter' arguments error. : #{symbol}, #{filter_or_condition} at #{ call_from }"
|
155
157
|
end
|
156
158
|
end
|
157
159
|
end
|
data/lib/mongous/filter.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
module Mongous
|
3
3
|
module Extention
|
4
4
|
def count
|
5
|
-
|
5
|
+
# self.collection.find.count
|
6
|
+
self.collection.estimated_document_count
|
6
7
|
end
|
7
8
|
|
8
9
|
def first
|
@@ -175,7 +176,7 @@ module Mongous
|
|
175
176
|
|
176
177
|
def do_find
|
177
178
|
_filter = @filter
|
178
|
-
_option = @option
|
179
|
+
_option = @option.dup
|
179
180
|
_option[:projection] = @projection if @projection
|
180
181
|
found = @klass.collection.find( _filter, _option )
|
181
182
|
found = found.sort( @sort ) if @sort
|
@@ -185,7 +186,10 @@ module Mongous
|
|
185
186
|
end
|
186
187
|
|
187
188
|
def count
|
188
|
-
|
189
|
+
found = @klass.collection.find( @filter )
|
190
|
+
found = found.skip( @skip ) if @skip
|
191
|
+
found = found.limit( @limit ) if @limit
|
192
|
+
_count = found.count_documents
|
189
193
|
if @skip
|
190
194
|
if @skip > _count
|
191
195
|
0
|
@@ -219,8 +223,7 @@ module Mongous
|
|
219
223
|
end
|
220
224
|
|
221
225
|
def delete
|
222
|
-
|
223
|
-
@klass.collection.delete_many( _filter )
|
226
|
+
@klass.collection.delete_many( @filter )
|
224
227
|
end
|
225
228
|
end
|
226
229
|
end
|
data/lib/mongous/version.rb
CHANGED
data/sample/declare_compact_1.rb
CHANGED
@@ -10,9 +10,10 @@ end
|
|
10
10
|
|
11
11
|
book = Book.new
|
12
12
|
book.title = "declare compact"
|
13
|
-
book.author = "
|
13
|
+
book.author = "Alice"
|
14
14
|
book.publisher = nil
|
15
|
-
book.style = "
|
15
|
+
book.style = "hardcover"
|
16
|
+
book.size = "A4"
|
16
17
|
book.price = 100
|
17
18
|
book.page = 100
|
18
19
|
# book.publish_at = nil # (default)
|
data/sample/declare_label_1.rb
CHANGED
@@ -10,6 +10,7 @@ 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
16
|
field :publish_at
|
@@ -22,9 +23,10 @@ end
|
|
22
23
|
|
23
24
|
book = Book.new
|
24
25
|
book.title = "declare label"
|
25
|
-
book.author = "
|
26
|
+
book.author = "Bob"
|
26
27
|
book.publisher = nil
|
27
|
-
book.style = "
|
28
|
+
book.style = "softcover"
|
29
|
+
book.size = "A5"
|
28
30
|
book.price = 200
|
29
31
|
book.page = 200
|
30
32
|
# book.publish_at = nil # (default)
|
data/sample/declare_ndex_1.rb
CHANGED
@@ -10,6 +10,7 @@ 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
16
|
field :publish_at
|
@@ -24,9 +25,10 @@ end
|
|
24
25
|
|
25
26
|
book = Book.new
|
26
27
|
book.title = "declare index 1"
|
27
|
-
book.author = "
|
28
|
+
book.author = "Candy"
|
28
29
|
book.publisher = nil
|
29
|
-
book.style = "
|
30
|
+
book.style = "paperback"
|
31
|
+
book.size = "A6"
|
30
32
|
book.price = 300
|
31
33
|
book.page = 300
|
32
34
|
# book.publish_at = nil # (default)
|
data/sample/declare_ndex_2.rb
CHANGED
@@ -10,6 +10,7 @@ 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
16
|
field :publish_at
|
@@ -24,9 +25,10 @@ end
|
|
24
25
|
|
25
26
|
book = Book.new
|
26
27
|
book.title = "declare index 2"
|
27
|
-
book.author = "
|
28
|
+
book.author = "Candy"
|
28
29
|
book.publisher = nil
|
29
|
-
book.style = "
|
30
|
+
book.style = "paperback"
|
31
|
+
book.size = "A6"
|
30
32
|
book.price = 300
|
31
33
|
book.page = 300
|
32
34
|
# book.publish_at = nil # (default)
|
data/sample/declare_strict_1.rb
CHANGED
@@ -9,13 +9,14 @@ class Book
|
|
9
9
|
field :title, String, :must
|
10
10
|
field :author, String
|
11
11
|
field :publisher, String
|
12
|
-
field :style, String, %w[
|
12
|
+
field :style, String, %w[hardcover softcover paperback]
|
13
|
+
field :size, String, /[AB]\d/
|
13
14
|
field :price, Integer, (0..1_000_000)
|
14
15
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
16
|
field :isbn, String, proc{ isbn? }
|
16
17
|
field :lang, String, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
20
|
|
20
21
|
verify :strict
|
21
22
|
verify { having?( title ) }
|
@@ -31,11 +32,12 @@ end
|
|
31
32
|
|
32
33
|
book = Book.new
|
33
34
|
book.title = "declare strict"
|
34
|
-
book.author = "
|
35
|
+
book.author = "David"
|
35
36
|
book.publisher = nil
|
36
|
-
book.style = "
|
37
|
-
book.
|
38
|
-
book.
|
37
|
+
book.style = "paperback"
|
38
|
+
book.size = "A7"
|
39
|
+
book.price = 400
|
40
|
+
book.page = 400
|
39
41
|
book.isbn = "978-3-16-148410-0"
|
40
42
|
# book.lang = nil # (default)
|
41
43
|
# book.created_at = nil # (create)
|
data/sample/declare_strict_2.rb
CHANGED
@@ -9,13 +9,14 @@ class Book
|
|
9
9
|
field :title, String, :must
|
10
10
|
field :author, String
|
11
11
|
field :publisher, String, :must
|
12
|
-
field :style, String, %w[
|
12
|
+
field :style, String, %w[hardcover softcover paperback]
|
13
|
+
field :size, String, /[AB]\d/
|
13
14
|
field :price, Integer, (0..1_000_000)
|
14
15
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
16
|
field :isbn, String, proc{ isbn? }
|
16
17
|
field :lang, String, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
20
|
|
20
21
|
verify :strict
|
21
22
|
|
@@ -14,6 +14,7 @@ class Book2
|
|
14
14
|
field :author
|
15
15
|
field :publisher
|
16
16
|
field :style
|
17
|
+
field :size
|
17
18
|
field :price
|
18
19
|
field :page
|
19
20
|
field :isbn
|
@@ -30,13 +31,14 @@ class Book3
|
|
30
31
|
field :title, :must
|
31
32
|
field :author
|
32
33
|
field :publisher, String, :must
|
33
|
-
field :style, String, %w[
|
34
|
+
field :style, String, %w[hardcover softcover paperback]
|
35
|
+
field :size, String, /[AB]\d/
|
34
36
|
field :price, Integer, (0..1_000_000)
|
35
37
|
field :page, Integer, proc{ page > 0 }
|
36
38
|
field :isbn, proc{ isbn? }
|
37
39
|
field :lang, String, default: "en"
|
38
|
-
field :created_at, Time, create:
|
39
|
-
field :updated_at, Time, update:
|
40
|
+
field :created_at, Time, create: proc{ Time.now }
|
41
|
+
field :updated_at, Time, update: proc{ Time.now }
|
40
42
|
|
41
43
|
verify :strict
|
42
44
|
verify { having?( title ) }
|
data/sample/query_basic_4.rb
CHANGED
@@ -7,17 +7,17 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
Book.where(
|
10
|
+
Book.where( size: %w[A4 A5 A6] ).each do |book|
|
11
11
|
p book
|
12
12
|
end
|
13
13
|
puts
|
14
14
|
|
15
|
-
Book.where(
|
15
|
+
Book.where( size: %w[A4 A5]).each do |book|
|
16
16
|
p book
|
17
17
|
end
|
18
18
|
puts
|
19
19
|
|
20
|
-
Book.where(
|
20
|
+
Book.where( size: %w[A5] ).each do |book|
|
21
21
|
p book
|
22
22
|
end
|
23
23
|
puts
|
data/sample/query_detail_1.rb
CHANGED
data/sample/query_detail_2.rb
CHANGED
data/sample/query_detail_3.rb
CHANGED
@@ -9,13 +9,14 @@ class Book
|
|
9
9
|
field :title, :must
|
10
10
|
field :author
|
11
11
|
field :publisher
|
12
|
-
field :style, %w[
|
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
16
|
field :isbn, proc{ isbn? }
|
16
17
|
field :lang, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
20
|
|
20
21
|
verify :strict
|
21
22
|
|
data/sample/query_filter_1.rb
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
(1..3).each do |n|
|
11
11
|
unless Book.where( title: "complex #{n}" ).first
|
12
|
-
Book.create( title: "complex #{n}", author: (0x40 + n).chr,
|
12
|
+
Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
|
13
13
|
end
|
14
14
|
end
|
15
15
|
puts
|
data/sample/query_filter_2.rb
CHANGED
@@ -8,12 +8,12 @@ class Book
|
|
8
8
|
|
9
9
|
filter :title1, { title: /filter/ }
|
10
10
|
filter :price1, { price: (2000..3000) }
|
11
|
-
filter :page1, where(
|
11
|
+
filter :page1, where( size: %w[A3 A4] )
|
12
12
|
end
|
13
13
|
|
14
14
|
(1..5).each do |n|
|
15
15
|
unless Book.where( title: "filter #{n}" ).first
|
16
|
-
Book.create( title: "filter #{n}", author: (0x40 + n).chr,
|
16
|
+
Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
|
17
17
|
end
|
18
18
|
end
|
19
19
|
puts
|
@@ -3,35 +3,45 @@ require "mongous"
|
|
3
3
|
|
4
4
|
Mongous.connect!
|
5
5
|
|
6
|
-
class
|
6
|
+
class Item
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
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
|
11
21
|
puts
|
12
22
|
|
13
|
-
p count =
|
23
|
+
p count = Item.where[0..4].count
|
14
24
|
puts
|
15
25
|
|
16
|
-
p count =
|
26
|
+
p count = Item.where[0...4].count
|
17
27
|
puts
|
18
28
|
|
19
|
-
p count =
|
29
|
+
p count = Item.where[0, 4].count
|
20
30
|
puts
|
21
31
|
|
22
|
-
p count =
|
32
|
+
p count = Item.where[5, 5].count
|
23
33
|
puts
|
24
34
|
|
25
|
-
pp books =
|
35
|
+
pp books = Item.where[0, 2].all
|
26
36
|
puts
|
27
37
|
|
28
|
-
filter =
|
29
|
-
filter[0, 4].each do |
|
30
|
-
p
|
38
|
+
filter = Item.where
|
39
|
+
filter[0, 4].each do |item|
|
40
|
+
p item
|
31
41
|
end
|
32
42
|
puts
|
33
|
-
filter[4, 4].each do |
|
34
|
-
p
|
43
|
+
filter[4, 4].each do |item|
|
44
|
+
p item
|
35
45
|
end
|
36
46
|
puts
|
37
47
|
|
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
@@ -10,6 +10,7 @@ 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
16
|
field :isbn
|
@@ -24,7 +25,8 @@ book = Book.new
|
|
24
25
|
book.title = "title detail 1"
|
25
26
|
book.author = "Alice"
|
26
27
|
book.publisher = "Foobar"
|
27
|
-
book.style = "
|
28
|
+
book.style = "hardcover"
|
29
|
+
book.size = "A4"
|
28
30
|
book.price = 1000
|
29
31
|
book.page = 100
|
30
32
|
book.isbn = "978-3-16-148410-0"
|
data/sample/save_detail_2.rb
CHANGED
@@ -10,6 +10,7 @@ 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
16
|
field :isbn
|
@@ -24,7 +25,8 @@ book = Book.new
|
|
24
25
|
book.title = "title detail 2"
|
25
26
|
book.author = "Bob"
|
26
27
|
book.publisher = "Foobar"
|
27
|
-
book.style = "
|
28
|
+
book.style = "softcover"
|
29
|
+
book.size = "A5"
|
28
30
|
book.price = 2000
|
29
31
|
book.page = 200
|
30
32
|
book.isbn = "978-3-16-148410-0"
|
data/sample/save_detail_3.rb
CHANGED
@@ -9,13 +9,14 @@ class Book
|
|
9
9
|
field :title, :must
|
10
10
|
field :author
|
11
11
|
field :publisher
|
12
|
-
field :style, %w[
|
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
16
|
field :isbn, proc{ isbn? }
|
16
17
|
field :lang, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
20
|
|
20
21
|
verify :strict
|
21
22
|
|
@@ -30,7 +31,8 @@ book = Book.new
|
|
30
31
|
book.title = "title detail 3"
|
31
32
|
book.author = "Candy"
|
32
33
|
#book.publisher
|
33
|
-
book.style = "
|
34
|
+
book.style = "paperback"
|
35
|
+
book.size = "A6"
|
34
36
|
book.price = 3000
|
35
37
|
book.page = 300
|
36
38
|
book.isbn = "978-3-16-148410-0"
|
data/sample/save_verify_1.rb
CHANGED
@@ -9,7 +9,8 @@ class Book
|
|
9
9
|
field :title, String, :must
|
10
10
|
field :author, String
|
11
11
|
field :publisher, String
|
12
|
-
field :style, String, [
|
12
|
+
field :style, String, %w[hardcover softcover paperback]
|
13
|
+
field :size, String, /[AB]\d/
|
13
14
|
field :price, Integer, (0..1_000_000)
|
14
15
|
field :page, Integer, proc{ page > 0 }
|
15
16
|
field :isbn, String, proc{ isbn? }
|
@@ -34,7 +35,8 @@ begin
|
|
34
35
|
book = Book.new
|
35
36
|
book.title = "title verify 1"
|
36
37
|
book.author = "jane doe"
|
37
|
-
book.style = "
|
38
|
+
book.style = "softcover"
|
39
|
+
book.size = "A5"
|
38
40
|
book.price = 2000
|
39
41
|
book.page = 200
|
40
42
|
book.isbn = "978-3-16-148410-0"
|
data/sample/save_verify_5.rb
CHANGED
@@ -7,13 +7,13 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
|
9
9
|
field :title, :must
|
10
|
-
field :
|
10
|
+
field :size, String, /[AB]\d/
|
11
11
|
end
|
12
12
|
|
13
13
|
begin
|
14
14
|
book = Book.new
|
15
|
-
book.title = "title
|
16
|
-
book.
|
15
|
+
book.title = "title size"
|
16
|
+
book.size = "C5"
|
17
17
|
book.save
|
18
18
|
|
19
19
|
rescue => e
|
data/sample/save_verify_6.rb
CHANGED
@@ -7,13 +7,13 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
|
9
9
|
field :title, :must
|
10
|
-
field :
|
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
|
16
|
-
book.
|
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
|
+
|
data/sample/zap_basic_2.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.2.
|
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-
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -119,9 +119,10 @@ files:
|
|
119
119
|
- sample/save_verify_4.rb
|
120
120
|
- sample/save_verify_5.rb
|
121
121
|
- sample/save_verify_6.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
|