mongous 0.2.1 → 0.3.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 +80 -12
- data/README.ja.adoc +81 -13
- data/lib/mongous/base.rb +30 -0
- data/lib/mongous/document.rb +10 -2
- data/lib/mongous/version.rb +1 -1
- data/sample/declare_compact_1.rb +3 -4
- data/sample/declare_label_1.rb +5 -3
- data/sample/declare_ndex_1.rb +4 -2
- data/sample/declare_ndex_2.rb +5 -3
- data/sample/multi_collection_3.rb +26 -0
- data/sample/query_detail_1.rb +2 -1
- data/sample/query_detail_2.rb +2 -1
- data/sample/save_detail_3.rb +4 -4
- data/sample/save_verify_1.rb +2 -2
- data/sample/zap_basic_3.rb +11 -0
- data/sample/zbenchmark_search_1.rb +110 -0
- data/sample/zbenchmark_search_2.rb +110 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e316aaf87661c4fe27054cdbaef39ba7f21f24432b3752ffb1cb308894de5272
|
4
|
+
data.tar.gz: 5597f0a55efc8d1afa45e6bf9ee93ea77653d7161d12e776bc979a6543b2c94a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dc7ea514d20c8fc9ed8eaed86b4feb293df3e713a1db3acb60eb46abd61f28f0dbeeb9a68b9ac1442b6b690b3e4b12653bce102d007d912e6c08a700bd964ef
|
7
|
+
data.tar.gz: 44cfdfa61226dbfcaa40d846bfa2f00a76137b297141cbf4ea7318abdcc999271cddafd9e65bc5ea5d69745674da87aa719c2b34968d40968762d3f9e0855ced
|
data/README.adoc
CHANGED
@@ -9,8 +9,7 @@ Yet another mongo wrapper library.
|
|
9
9
|
* Check if the constraint conditions are met when saving the document.
|
10
10
|
* Check if the constraint condition is satisfied when setting the item value of the document.
|
11
11
|
* The contents of undefined items in the document can be described by value or Proc.
|
12
|
-
* Item
|
13
|
-
* Item settings can be described in values or Proc when updating the document.
|
12
|
+
* Item contents at the time of document creation and update can be described by value or Proc.
|
14
13
|
|
15
14
|
== Installation
|
16
15
|
|
@@ -40,10 +39,7 @@ Or install it yourself as:
|
|
40
39
|
require "mongous"
|
41
40
|
|
42
41
|
Mongous.connect!
|
43
|
-
|
44
|
-
class Book
|
45
|
-
include Mongous::Document
|
46
|
-
end
|
42
|
+
Mongous.attach! :Book
|
47
43
|
----
|
48
44
|
|
49
45
|
=== Detail declaration
|
@@ -57,7 +53,7 @@ Mongous.connect! ["localhost:27017"], database: "test"
|
|
57
53
|
class Book
|
58
54
|
include Mongous::Document
|
59
55
|
|
60
|
-
field :title, String,
|
56
|
+
field :title, String, :must
|
61
57
|
field :author, String
|
62
58
|
field :publisher, String
|
63
59
|
field :style, String, %w[hardcover, softcover, paperback]
|
@@ -191,7 +187,20 @@ Mongous.connect( hosts_or_uri = nil, **options )
|
|
191
187
|
* Result:
|
192
188
|
** Mongo::Client instance.
|
193
189
|
|
194
|
-
===
|
190
|
+
=== Define collection operate class with default settings.
|
191
|
+
|
192
|
+
[source,ruby]
|
193
|
+
----
|
194
|
+
Mongous.attach!( *names )
|
195
|
+
----
|
196
|
+
|
197
|
+
* Result:
|
198
|
+
** nil.
|
199
|
+
|
200
|
+
* Parameter:
|
201
|
+
** names: Collection names. (String or Symbol)
|
202
|
+
|
203
|
+
=== Include document functions into collection operate class.
|
195
204
|
|
196
205
|
[source,ruby]
|
197
206
|
----
|
@@ -296,7 +305,7 @@ filter( symbol, filter_or_cond )
|
|
296
305
|
|
297
306
|
[source,ruby]
|
298
307
|
----
|
299
|
-
where( filter = nil, **conditions )
|
308
|
+
Collection operate class #where( filter = nil, **conditions )
|
300
309
|
----
|
301
310
|
|
302
311
|
* Result:
|
@@ -310,7 +319,7 @@ where( filter = nil, **conditions )
|
|
310
319
|
|
311
320
|
[source,ruby]
|
312
321
|
----
|
313
|
-
not( filter = nil, **conditions )
|
322
|
+
Collection operate class #not( filter = nil, **conditions )
|
314
323
|
----
|
315
324
|
|
316
325
|
* Result:
|
@@ -324,7 +333,7 @@ not( filter = nil, **conditions )
|
|
324
333
|
|
325
334
|
[source,ruby]
|
326
335
|
----
|
327
|
-
and( *filters )
|
336
|
+
Collection operate class #and( *filters )
|
328
337
|
----
|
329
338
|
|
330
339
|
* Result:
|
@@ -337,7 +346,7 @@ and( *filters )
|
|
337
346
|
|
338
347
|
[source,ruby]
|
339
348
|
----
|
340
|
-
or( *filters )
|
349
|
+
Collection operate class #or( *filters )
|
341
350
|
----
|
342
351
|
|
343
352
|
* Result:
|
@@ -346,6 +355,65 @@ or( *filters )
|
|
346
355
|
* Parameter:
|
347
356
|
** filters: Field name symbol, or filter instance.
|
348
357
|
|
358
|
+
=== Save document.
|
359
|
+
|
360
|
+
[source,ruby]
|
361
|
+
----
|
362
|
+
Document operate object #save
|
363
|
+
----
|
364
|
+
|
365
|
+
* Result:
|
366
|
+
** nil.
|
367
|
+
|
368
|
+
=== Convert document to Hash.
|
369
|
+
|
370
|
+
[source,ruby]
|
371
|
+
----
|
372
|
+
Document operate object #to_hash
|
373
|
+
----
|
374
|
+
|
375
|
+
* Result:
|
376
|
+
** Hash object.
|
377
|
+
|
378
|
+
=== Convert document to JSON.
|
379
|
+
|
380
|
+
[source,ruby]
|
381
|
+
----
|
382
|
+
Document operate object #to_hash
|
383
|
+
----
|
384
|
+
|
385
|
+
* Result:
|
386
|
+
** JSON String.
|
387
|
+
|
388
|
+
=== Read document field.
|
389
|
+
|
390
|
+
[source,ruby]
|
391
|
+
----
|
392
|
+
Document operate object #[]( field_name )
|
393
|
+
Document operate object #field_name
|
394
|
+
----
|
395
|
+
|
396
|
+
* Result:
|
397
|
+
** field_value.
|
398
|
+
|
399
|
+
* Parameter:
|
400
|
+
** field_name: Field name.
|
401
|
+
|
402
|
+
=== Write document field.
|
403
|
+
|
404
|
+
[source,ruby]
|
405
|
+
----
|
406
|
+
Document operate object #[]=( field_name, field_value )
|
407
|
+
Document operate object #field_name = field_value
|
408
|
+
----
|
409
|
+
|
410
|
+
* Result:
|
411
|
+
** field_value.
|
412
|
+
|
413
|
+
* Parameter:
|
414
|
+
** field_name: Field name.
|
415
|
+
** field_value: Field value.
|
416
|
+
|
349
417
|
== Contributing
|
350
418
|
|
351
419
|
Bug reports and pull requests are welcome on GitHub at https://github.com/arimay/mongous.
|
data/README.ja.adoc
CHANGED
@@ -4,13 +4,12 @@
|
|
4
4
|
|
5
5
|
== 特徴
|
6
6
|
|
7
|
-
* 組込みと標準添付を除いて、mongo driver と bson
|
7
|
+
* 組込みと標準添付を除いて、mongo driver と bson のみに依存する軽いライブラリである.
|
8
8
|
* ドキュメント項目の制約条件を Array, Range, Regexp, Proc インスタンスまたは基本クラスで記述できる.
|
9
9
|
* ドキュメント保存時に制約条件を満たすか検査する.
|
10
10
|
* ドキュメントの項目値設定時に制約条件を満たすか検査する.
|
11
11
|
* ドキュメントの未定義項目の内容を値または Proc で記述できる.
|
12
|
-
*
|
13
|
-
* ドキュメントの更新時に項目設定内容を値または Proc で記述できる.
|
12
|
+
* ドキュメント作成時および更新時の項目内容を値または Proc で記述できる.
|
14
13
|
|
15
14
|
== 導入
|
16
15
|
|
@@ -33,17 +32,14 @@ gem 'mongous'
|
|
33
32
|
|
34
33
|
== 使い方
|
35
34
|
|
36
|
-
===
|
35
|
+
=== 簡潔な定義
|
37
36
|
|
38
37
|
[source,ruby]
|
39
38
|
----
|
40
39
|
require "mongous"
|
41
40
|
|
42
41
|
Mongous.connect!
|
43
|
-
|
44
|
-
class Book
|
45
|
-
include Mongous::Document
|
46
|
-
end
|
42
|
+
Mongous.attach! :Book
|
47
43
|
----
|
48
44
|
|
49
45
|
=== 詳細な定義
|
@@ -191,7 +187,20 @@ Mongous.connect( hosts_or_uri = nil, **options )
|
|
191
187
|
* Result:
|
192
188
|
** Mongo::Client インスタンス.
|
193
189
|
|
194
|
-
===
|
190
|
+
=== コレクション操作クラスをデフォルト設定で定義する.
|
191
|
+
|
192
|
+
[source,ruby]
|
193
|
+
----
|
194
|
+
Mongous.attach!( *names )
|
195
|
+
----
|
196
|
+
|
197
|
+
* Result:
|
198
|
+
** nil.
|
199
|
+
|
200
|
+
* Parameter:
|
201
|
+
** names: コレクション名. (String または Symbol)
|
202
|
+
|
203
|
+
=== コレクション操作クラスにドキュメントの機能を取り入れる.
|
195
204
|
|
196
205
|
[source,ruby]
|
197
206
|
----
|
@@ -296,7 +305,7 @@ filter( symbol, filter_or_cond )
|
|
296
305
|
|
297
306
|
[source,ruby]
|
298
307
|
----
|
299
|
-
where( filter = nil, **conditions )
|
308
|
+
コレクション操作クラス #where( filter = nil, **conditions )
|
300
309
|
----
|
301
310
|
|
302
311
|
* Result:
|
@@ -310,7 +319,7 @@ where( filter = nil, **conditions )
|
|
310
319
|
|
311
320
|
[source,ruby]
|
312
321
|
----
|
313
|
-
not( filter = nil, **conditions )
|
322
|
+
コレクション操作クラス #not( filter = nil, **conditions )
|
314
323
|
----
|
315
324
|
|
316
325
|
* Result:
|
@@ -324,7 +333,7 @@ not( filter = nil, **conditions )
|
|
324
333
|
|
325
334
|
[source,ruby]
|
326
335
|
----
|
327
|
-
and( *filters )
|
336
|
+
コレクション操作クラス #and( *filters )
|
328
337
|
----
|
329
338
|
|
330
339
|
* Result:
|
@@ -337,7 +346,7 @@ and( *filters )
|
|
337
346
|
|
338
347
|
[source,ruby]
|
339
348
|
----
|
340
|
-
or( *filters )
|
349
|
+
コレクション操作クラス #or( *filters )
|
341
350
|
----
|
342
351
|
|
343
352
|
* Result:
|
@@ -346,6 +355,65 @@ or( *filters )
|
|
346
355
|
* Parameter:
|
347
356
|
** filters: 項目名またはフィルタインスタンス
|
348
357
|
|
358
|
+
=== ドキュメントを保存.
|
359
|
+
|
360
|
+
[source,ruby]
|
361
|
+
----
|
362
|
+
ドキュメント操作オブジェクト #save
|
363
|
+
----
|
364
|
+
|
365
|
+
* Result:
|
366
|
+
** nil.
|
367
|
+
|
368
|
+
=== ドキュメントをHashに変換.
|
369
|
+
|
370
|
+
[source,ruby]
|
371
|
+
----
|
372
|
+
ドキュメント操作オブジェクト #to_hash
|
373
|
+
----
|
374
|
+
|
375
|
+
* Result:
|
376
|
+
** Hash object.
|
377
|
+
|
378
|
+
=== ドキュメントをJSONに変換.
|
379
|
+
|
380
|
+
[source,ruby]
|
381
|
+
----
|
382
|
+
ドキュメント操作オブジェクト #to_hash
|
383
|
+
----
|
384
|
+
|
385
|
+
* Result:
|
386
|
+
** JSON String.
|
387
|
+
|
388
|
+
=== ドキュメントの項目値を読む.
|
389
|
+
|
390
|
+
[source,ruby]
|
391
|
+
----
|
392
|
+
ドキュメント操作オブジェクト #[]( field_name )
|
393
|
+
ドキュメント操作オブジェクト #field_name
|
394
|
+
----
|
395
|
+
|
396
|
+
* Result:
|
397
|
+
** 項目値.
|
398
|
+
|
399
|
+
* Parameter:
|
400
|
+
** field_name: 項目名.
|
401
|
+
|
402
|
+
=== ドキュメントの項目値を書く.
|
403
|
+
|
404
|
+
[source,ruby]
|
405
|
+
----
|
406
|
+
ドキュメント操作オブジェクト #[]=( field_name, field_value )
|
407
|
+
ドキュメント操作オブジェクト #field_name = field_value
|
408
|
+
----
|
409
|
+
|
410
|
+
* Result:
|
411
|
+
** 項目値.
|
412
|
+
|
413
|
+
* Parameter:
|
414
|
+
** field_name: 項目名.
|
415
|
+
** field_value: 項目値.
|
416
|
+
|
349
417
|
== 貢献
|
350
418
|
|
351
419
|
不具合報告とプルリクエストは GitHub https://github.com/arimay/mongous まで.
|
data/lib/mongous/base.rb
CHANGED
@@ -50,6 +50,36 @@ module Mongous
|
|
50
50
|
self.class_variable_set( :@@client, _client )
|
51
51
|
end
|
52
52
|
|
53
|
+
def attach!( *names )
|
54
|
+
raise Mongous::Error, "missing argument." if names.empty?
|
55
|
+
|
56
|
+
names.each do |name|
|
57
|
+
case name
|
58
|
+
when String
|
59
|
+
when Symbol
|
60
|
+
name = name.to_s
|
61
|
+
else
|
62
|
+
raise Mongous::Error, "type invalid. : #{ name }"
|
63
|
+
end
|
64
|
+
|
65
|
+
raise Mongous::Error, "missing argument." unless /^[A-Z]/.match(name)
|
66
|
+
|
67
|
+
if Object.const_defined?( name )
|
68
|
+
if Object.const_get( name ).include?( Mongous::Document )
|
69
|
+
Object.class_eval{ remove_const( name ) }
|
70
|
+
else
|
71
|
+
raise Mongous::Error, "type invalid. : #{ Object.class_eval(name) }"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Object.class_eval <<-CLASS
|
76
|
+
class #{name}
|
77
|
+
include Mongous::Document
|
78
|
+
end
|
79
|
+
CLASS
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
53
83
|
def client
|
54
84
|
self.class_variable_get( :@@client ) rescue nil
|
55
85
|
end
|
data/lib/mongous/document.rb
CHANGED
@@ -100,15 +100,23 @@ module Mongous
|
|
100
100
|
when :update
|
101
101
|
self.class.collection.update_one( { "_id"=> @doc["_id"] }, { '$set' => @doc } )
|
102
102
|
end
|
103
|
-
|
104
103
|
self
|
105
104
|
end
|
106
105
|
|
106
|
+
def to_hash
|
107
|
+
@doc.dup
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_json
|
111
|
+
@doc.to_json
|
112
|
+
end
|
113
|
+
|
107
114
|
def []( label )
|
108
115
|
label = label.to_s
|
109
116
|
|
110
117
|
if self.class.symbols[:strict]
|
111
|
-
|
118
|
+
labels = ["_id"] + self.class.fields.keys
|
119
|
+
if !labels.include?( label )
|
112
120
|
raise Mongous::Error, "undefined field. : #{ label }"
|
113
121
|
end
|
114
122
|
end
|
data/lib/mongous/version.rb
CHANGED
data/sample/declare_compact_1.rb
CHANGED
@@ -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 = "declare compact"
|
13
12
|
book.author = "Alice"
|
@@ -16,12 +15,12 @@ book.style = "hardcover"
|
|
16
15
|
book.size = "A4"
|
17
16
|
book.price = 100
|
18
17
|
book.page = 100
|
19
|
-
|
20
|
-
# book.isbn = "978-3-16-148410-0"
|
18
|
+
book.isbn = "978-3-16-148410-0"
|
21
19
|
# book.lang = nil # (default)
|
20
|
+
# book.created_at = nil # (created)
|
21
|
+
# book.updated_at = nil # (updated)
|
22
22
|
book.save
|
23
23
|
|
24
|
-
|
25
24
|
Book.each do |book|
|
26
25
|
pp book
|
27
26
|
end
|
data/sample/declare_label_1.rb
CHANGED
@@ -13,9 +13,10 @@ class Book
|
|
13
13
|
field :size
|
14
14
|
field :price
|
15
15
|
field :page
|
16
|
-
field :publish_at
|
17
16
|
field :isbn
|
18
17
|
field :lang
|
18
|
+
field :created_at
|
19
|
+
field :updated_at
|
19
20
|
|
20
21
|
verify :strict
|
21
22
|
end
|
@@ -29,9 +30,10 @@ book.style = "softcover"
|
|
29
30
|
book.size = "A5"
|
30
31
|
book.price = 200
|
31
32
|
book.page = 200
|
32
|
-
|
33
|
-
# book.isbn = "978-3-16-148410-0"
|
33
|
+
book.isbn = "978-3-16-148410-0"
|
34
34
|
# book.lang = nil # (default)
|
35
|
+
# book.created_at = nil # (created)
|
36
|
+
# book.updated_at = nil # (updated)
|
35
37
|
book.save
|
36
38
|
|
37
39
|
|
data/sample/declare_ndex_1.rb
CHANGED
@@ -13,9 +13,10 @@ class Book
|
|
13
13
|
field :size
|
14
14
|
field :price
|
15
15
|
field :page
|
16
|
-
field :publish_at
|
17
16
|
field :isbn
|
18
17
|
field :lang
|
18
|
+
field :created_at
|
19
|
+
field :updated_at
|
19
20
|
|
20
21
|
index :title
|
21
22
|
|
@@ -31,9 +32,10 @@ book.style = "paperback"
|
|
31
32
|
book.size = "A6"
|
32
33
|
book.price = 300
|
33
34
|
book.page = 300
|
34
|
-
# book.publish_at = nil # (default)
|
35
35
|
book.isbn = "978-3-16-148410-0"
|
36
36
|
# book.lang = nil # (default)
|
37
|
+
# book.created_at = nil # (created)
|
38
|
+
# book.updated_at = nil # (updated)
|
37
39
|
book.save
|
38
40
|
|
39
41
|
|
data/sample/declare_ndex_2.rb
CHANGED
@@ -13,11 +13,12 @@ class Book
|
|
13
13
|
field :size
|
14
14
|
field :price
|
15
15
|
field :page
|
16
|
-
field :publish_at
|
17
16
|
field :isbn
|
18
17
|
field :lang
|
18
|
+
field :created_at
|
19
|
+
field :updated_at
|
19
20
|
|
20
|
-
index :isbn
|
21
|
+
index :isbn
|
21
22
|
|
22
23
|
verify :strict
|
23
24
|
end
|
@@ -31,9 +32,10 @@ book.style = "paperback"
|
|
31
32
|
book.size = "A6"
|
32
33
|
book.price = 300
|
33
34
|
book.page = 300
|
34
|
-
# book.publish_at = nil # (default)
|
35
35
|
book.isbn = "978-3-16-148410-0"
|
36
36
|
# book.lang = nil # (default)
|
37
|
+
# book.created_at = nil # (created)
|
38
|
+
# book.updated_at = nil # (updated)
|
37
39
|
book.save
|
38
40
|
|
39
41
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
Mongous.attach! :Book1
|
7
|
+
Mongous.attach! :Book2
|
8
|
+
Mongous.attach! :Book3
|
9
|
+
|
10
|
+
pp Book1.collection
|
11
|
+
pp Book2.collection
|
12
|
+
pp Book3.collection
|
13
|
+
|
14
|
+
Mongous.attach! :Book1
|
15
|
+
Mongous.attach! :Book2, :Book3
|
16
|
+
|
17
|
+
pp Book1.collection
|
18
|
+
pp Book2.collection
|
19
|
+
pp Book3.collection
|
20
|
+
|
21
|
+
Mongous.attach! :Book1, :Book2, :Book3
|
22
|
+
|
23
|
+
pp Book1.collection
|
24
|
+
pp Book2.collection
|
25
|
+
pp Book3.collection
|
26
|
+
|
data/sample/query_detail_1.rb
CHANGED
data/sample/query_detail_2.rb
CHANGED
data/sample/save_detail_3.rb
CHANGED
@@ -30,14 +30,14 @@ end
|
|
30
30
|
book = Book.new
|
31
31
|
book.title = "title detail 3"
|
32
32
|
book.author = "Candy"
|
33
|
-
|
33
|
+
book.publisher
|
34
34
|
book.style = "paperback"
|
35
35
|
book.size = "A6"
|
36
36
|
book.price = 3000
|
37
37
|
book.page = 300
|
38
38
|
book.isbn = "978-3-16-148410-0"
|
39
|
-
#book.lang
|
40
|
-
#book.created_at
|
41
|
-
#book.updated_at
|
39
|
+
# book.lang
|
40
|
+
# book.created_at
|
41
|
+
# book.updated_at
|
42
42
|
book.save
|
43
43
|
|
data/sample/save_verify_1.rb
CHANGED
@@ -15,8 +15,8 @@ class Book
|
|
15
15
|
field :page, Integer, proc{ page > 0 }
|
16
16
|
field :isbn, String, proc{ isbn? }
|
17
17
|
field :lang, String, default: "en"
|
18
|
-
field :created_at, Time, create:
|
19
|
-
field :updated_at, Time, update:
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
20
20
|
|
21
21
|
verify :strict
|
22
22
|
verify { having?( title ) }
|
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
class Card
|
7
|
+
include Mongous::Document
|
8
|
+
field :i1, Integer
|
9
|
+
field :i2, Integer
|
10
|
+
field :f1, Float
|
11
|
+
field :f2, Float
|
12
|
+
field :s1, String
|
13
|
+
field :s2, String
|
14
|
+
field :d1, Date
|
15
|
+
field :d2, Date
|
16
|
+
field :t1, Time
|
17
|
+
field :t2, Time
|
18
|
+
|
19
|
+
index :i2, unique: true
|
20
|
+
index :f2, unique: true
|
21
|
+
index :s2, unique: true
|
22
|
+
index :d2, unique: true
|
23
|
+
index :t2, unique: true
|
24
|
+
end
|
25
|
+
|
26
|
+
require "benchmark"
|
27
|
+
require "date"
|
28
|
+
|
29
|
+
COUNT = 10000
|
30
|
+
|
31
|
+
D0 = Date.parse( "2020-01-01" )
|
32
|
+
T0 = D0.to_time
|
33
|
+
|
34
|
+
Benchmark.bm 32 do |r|
|
35
|
+
if COUNT != Card.count
|
36
|
+
Card.delete
|
37
|
+
r.report "create #{COUNT}" do
|
38
|
+
(0...COUNT).each do |i|
|
39
|
+
f = i.to_f
|
40
|
+
s = i.to_s
|
41
|
+
d = D0 + i
|
42
|
+
t = T0 + i
|
43
|
+
card = Card.create(
|
44
|
+
i1: i,
|
45
|
+
i2: i,
|
46
|
+
f1: f,
|
47
|
+
f2: f,
|
48
|
+
s1: s,
|
49
|
+
s2: s,
|
50
|
+
d1: d,
|
51
|
+
d2: d,
|
52
|
+
t1: t,
|
53
|
+
t2: t,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
r.report "find a integer without index" do
|
60
|
+
(0...COUNT).each do |i|
|
61
|
+
Card.where( i1: i ).first
|
62
|
+
end
|
63
|
+
end
|
64
|
+
r.report "find a integer with index" do
|
65
|
+
(0...COUNT).each do |i|
|
66
|
+
Card.where( i2: i ).first
|
67
|
+
end
|
68
|
+
end
|
69
|
+
r.report "find a float without index" do
|
70
|
+
(0...COUNT).each do |i|
|
71
|
+
Card.where( f1: i.to_f ).first
|
72
|
+
end
|
73
|
+
end
|
74
|
+
r.report "find a float with index" do
|
75
|
+
(0...COUNT).each do |i|
|
76
|
+
Card.where( f2: i.to_f ).first
|
77
|
+
end
|
78
|
+
end
|
79
|
+
r.report "find a string without index" do
|
80
|
+
(0...COUNT).each do |i|
|
81
|
+
Card.where( s1: i.to_s ).first
|
82
|
+
end
|
83
|
+
end
|
84
|
+
r.report "find a string with index" do
|
85
|
+
(0...COUNT).each do |i|
|
86
|
+
Card.where( s2: i.to_s ).first
|
87
|
+
end
|
88
|
+
end
|
89
|
+
r.report "find a date without index" do
|
90
|
+
(0...COUNT).each do |i|
|
91
|
+
Card.where( d1: D0 + i ).first
|
92
|
+
end
|
93
|
+
end
|
94
|
+
r.report "find a date with index" do
|
95
|
+
(0...COUNT).each do |i|
|
96
|
+
Card.where( d2: D0 + i ).first
|
97
|
+
end
|
98
|
+
end
|
99
|
+
r.report "find a time without index" do
|
100
|
+
(0...COUNT).each do |i|
|
101
|
+
Card.where( t1: T0 + i ).first
|
102
|
+
end
|
103
|
+
end
|
104
|
+
r.report "find a time with index" do
|
105
|
+
(0...COUNT).each do |i|
|
106
|
+
Card.where( t2: T0 + i ).first
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
class Card
|
7
|
+
include Mongous::Document
|
8
|
+
field :i1, Integer
|
9
|
+
field :i2, Integer
|
10
|
+
field :f1, Float
|
11
|
+
field :f2, Float
|
12
|
+
field :s1, String
|
13
|
+
field :s2, String
|
14
|
+
field :d1, Date
|
15
|
+
field :d2, Date
|
16
|
+
field :t1, Time
|
17
|
+
field :t2, Time
|
18
|
+
|
19
|
+
index :i2, unique: true
|
20
|
+
index :f2, unique: true
|
21
|
+
index :s2, unique: true
|
22
|
+
index :d2, unique: true
|
23
|
+
index :t2, unique: true
|
24
|
+
end
|
25
|
+
|
26
|
+
require "benchmark"
|
27
|
+
require "date"
|
28
|
+
|
29
|
+
COUNT = 10000
|
30
|
+
|
31
|
+
D0 = Date.parse( "2020-01-01" )
|
32
|
+
T0 = D0.to_time
|
33
|
+
|
34
|
+
Benchmark.bm 32 do |r|
|
35
|
+
if COUNT != Card.count
|
36
|
+
Card.delete
|
37
|
+
r.report "create #{COUNT}" do
|
38
|
+
(0...COUNT).each do |i|
|
39
|
+
f = i.to_f
|
40
|
+
s = i.to_s
|
41
|
+
d = D0 + i
|
42
|
+
t = T0 + i
|
43
|
+
card = Card.create(
|
44
|
+
i1: i,
|
45
|
+
i2: i,
|
46
|
+
f1: f,
|
47
|
+
f2: f,
|
48
|
+
s1: s,
|
49
|
+
s2: s,
|
50
|
+
d1: d,
|
51
|
+
d2: d,
|
52
|
+
t1: t,
|
53
|
+
t2: t,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
r.report "find range integer without index" do
|
60
|
+
(0...COUNT).each do |i|
|
61
|
+
Card.where( i1: ( i ... (i+10) ) ).all
|
62
|
+
end
|
63
|
+
end
|
64
|
+
r.report "find range integer with index" do
|
65
|
+
(0...COUNT).each do |i|
|
66
|
+
Card.where( i2: ( i ... (i+10) ) ).all
|
67
|
+
end
|
68
|
+
end
|
69
|
+
r.report "find range float without index" do
|
70
|
+
(0...COUNT).each do |i|
|
71
|
+
Card.where( f1: ( i.to_f ... (i+10).to_f ) ).all
|
72
|
+
end
|
73
|
+
end
|
74
|
+
r.report "find range float with index" do
|
75
|
+
(0...COUNT).each do |i|
|
76
|
+
Card.where( f2: ( i.to_f ... (i+10).to_f ) ).all
|
77
|
+
end
|
78
|
+
end
|
79
|
+
r.report "find range string without index" do
|
80
|
+
(0...COUNT).each do |i|
|
81
|
+
Card.where( s1: ( i.to_s ... (i+10).to_s ) ).all
|
82
|
+
end
|
83
|
+
end
|
84
|
+
r.report "find range string with index" do
|
85
|
+
(0...COUNT).each do |i|
|
86
|
+
Card.where( s2: ( i.to_s ... (i+10).to_s ) ).all
|
87
|
+
end
|
88
|
+
end
|
89
|
+
r.report "find range date without index" do
|
90
|
+
(0...COUNT).each do |i|
|
91
|
+
Card.where( d1: ( (D0 + i) ... (D0 + i + 10) ) ).all
|
92
|
+
end
|
93
|
+
end
|
94
|
+
r.report "find range date with index" do
|
95
|
+
(0...COUNT).each do |i|
|
96
|
+
Card.where( d2: ( (D0 + i) ... (D0 + i + 10) ) ).all
|
97
|
+
end
|
98
|
+
end
|
99
|
+
r.report "find range time without index" do
|
100
|
+
(0...COUNT).each do |i|
|
101
|
+
Card.where( t1: ( (T0 + i) ... (T0 + i + 10) ) ).all
|
102
|
+
end
|
103
|
+
end
|
104
|
+
r.report "find range time with index" do
|
105
|
+
(0...COUNT).each do |i|
|
106
|
+
Card.where( t2: ( (T0 + i) ... (T0 + i + 10) ) ).all
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
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.3.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-
|
11
|
+
date: 2020-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- sample/declare_strict_2.rb
|
93
93
|
- sample/multi_collection_1.rb
|
94
94
|
- sample/multi_collection_2.rb
|
95
|
+
- sample/multi_collection_3.rb
|
95
96
|
- sample/query_basic_1.rb
|
96
97
|
- sample/query_basic_2.rb
|
97
98
|
- sample/query_basic_3.rb
|
@@ -123,6 +124,9 @@ files:
|
|
123
124
|
- sample/update_basic_1.rb
|
124
125
|
- sample/zap_basic_1.rb
|
125
126
|
- sample/zap_basic_2.rb
|
127
|
+
- sample/zap_basic_3.rb
|
128
|
+
- sample/zbenchmark_search_1.rb
|
129
|
+
- sample/zbenchmark_search_2.rb
|
126
130
|
homepage: https://github.com/arimay/mongous
|
127
131
|
licenses:
|
128
132
|
- MIT
|