mongous 0.1.6 → 0.4.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 +296 -46
- data/README.ja.adoc +297 -47
- data/lib/mongous/base.rb +35 -2
- data/lib/mongous/document.rb +75 -32
- data/lib/mongous/extention.rb +72 -57
- data/lib/mongous/filter.rb +273 -208
- data/lib/mongous/version.rb +1 -1
- data/mongous.gemspec +1 -1
- data/sample/connect_auto_0.rb +9 -0
- 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 +7 -7
- data/sample/declare_label_1.rb +10 -6
- data/sample/declare_ndex_1.rb +9 -5
- data/sample/declare_ndex_2.rb +10 -6
- data/sample/declare_strict_1.rb +14 -10
- data/sample/declare_strict_2.rb +5 -3
- data/sample/{multi_docs_1.rb → multi_collection_1.rb} +0 -0
- data/sample/multi_collection_2.rb +63 -0
- data/sample/multi_collection_3.rb +26 -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_1.rb +3 -1
- data/sample/query_detail_2.rb +3 -1
- data/sample/query_detail_3.rb +5 -3
- data/sample/{query_basic_6.rb → query_filter_1.rb} +7 -4
- data/sample/query_filter_2.rb +50 -0
- data/sample/{query_super_1.rb → query_find_1.rb} +0 -1
- data/sample/query_select_1.rb +51 -0
- data/sample/query_skip_limit_1.rb +47 -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 +1 -2
- data/sample/save_basic_2.rb +1 -2
- data/sample/save_basic_3.rb +1 -2
- data/sample/save_detail_1.rb +7 -4
- data/sample/save_detail_2.rb +7 -4
- data/sample/save_detail_3.rb +11 -8
- data/sample/save_verify_1.rb +7 -4
- data/sample/save_verify_3.rb +1 -1
- 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
- data/sample/zap_basic_3.rb +2 -2
- data/sample/zbenchmark_search_1.rb +110 -0
- data/sample/zbenchmark_search_2.rb +110 -0
- data/sample/zbenchmark_search_3.rb +90 -0
- metadata +19 -12
- 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_projection_1.rb +0 -44
- data/sample/template_article.rb +0 -5
- data/sample/template_person.rb +0 -12
data/sample/save_verify_1.rb
CHANGED
@@ -9,12 +9,14 @@ 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
|
-
field :date, Date, &proc{ Date.today }
|
15
15
|
field :page, Integer, proc{ page > 0 }
|
16
16
|
field :isbn, String, proc{ isbn? }
|
17
|
-
field :lang, String,
|
17
|
+
field :lang, String, default: "en"
|
18
|
+
field :created_at, Time, create: proc{ Time.now }
|
19
|
+
field :updated_at, Time, update: proc{ Time.now }
|
18
20
|
|
19
21
|
verify :strict
|
20
22
|
verify { having?( title ) }
|
@@ -33,7 +35,8 @@ begin
|
|
33
35
|
book = Book.new
|
34
36
|
book.title = "title verify 1"
|
35
37
|
book.author = "jane doe"
|
36
|
-
book.style = "
|
38
|
+
book.style = "softcover"
|
39
|
+
book.size = "A5"
|
37
40
|
book.price = 2000
|
38
41
|
book.page = 200
|
39
42
|
book.isbn = "978-3-16-148410-0"
|
data/sample/save_verify_3.rb
CHANGED
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
data/sample/zap_basic_3.rb
CHANGED
@@ -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
|
+
|
@@ -0,0 +1,90 @@
|
|
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
|
+
field :r1, Float
|
19
|
+
field :r2, Float
|
20
|
+
|
21
|
+
index :i2, unique: true
|
22
|
+
index :f2, unique: true
|
23
|
+
index :s2, unique: true
|
24
|
+
index :d2, unique: true
|
25
|
+
index :t2, unique: true
|
26
|
+
index :r2
|
27
|
+
end
|
28
|
+
|
29
|
+
require "benchmark"
|
30
|
+
require "date"
|
31
|
+
|
32
|
+
COUNT = 100000
|
33
|
+
|
34
|
+
D0 = Date.parse( "2020-01-01" )
|
35
|
+
T0 = D0.to_time
|
36
|
+
|
37
|
+
Benchmark.bm 40 do |r|
|
38
|
+
if COUNT != Card.count
|
39
|
+
Card.delete
|
40
|
+
r.report "create #{COUNT}" do
|
41
|
+
(0...COUNT).each do |i|
|
42
|
+
f = i.to_f
|
43
|
+
s = i.to_s
|
44
|
+
d = D0 + i
|
45
|
+
t = T0 + i
|
46
|
+
rn = rand
|
47
|
+
card = Card.create(
|
48
|
+
i1: i,
|
49
|
+
i2: i,
|
50
|
+
f1: f,
|
51
|
+
f2: f,
|
52
|
+
s1: s,
|
53
|
+
s2: s,
|
54
|
+
d1: d,
|
55
|
+
d2: d,
|
56
|
+
t1: t,
|
57
|
+
t2: t,
|
58
|
+
r1: rn,
|
59
|
+
r2: rn,
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
r.report "first, order by asc without index" do
|
66
|
+
Card.where.sort( r1: 1 ).first
|
67
|
+
end
|
68
|
+
r.report "first, order by desc without index" do
|
69
|
+
Card.where.sort( r1: -1 ).first
|
70
|
+
end
|
71
|
+
r.report "top 10, order by asc without index" do
|
72
|
+
Card.where.sort( r1: 1 )[0,10].all
|
73
|
+
end
|
74
|
+
r.report "top 10, order by desc without index" do
|
75
|
+
Card.where.sort( r1: -1 )[0,10].all
|
76
|
+
end
|
77
|
+
r.report "first, order by asc with index" do
|
78
|
+
Card.where.sort( r2: 1 ).first
|
79
|
+
end
|
80
|
+
r.report "first, order by desc with index" do
|
81
|
+
Card.where.sort( r2: -1 ).first
|
82
|
+
end
|
83
|
+
r.report "top 10, order by asc with index" do
|
84
|
+
Card.where.sort( r2: 1 )[0,10].all
|
85
|
+
end
|
86
|
+
r.report "top 10, order by desc with index" do
|
87
|
+
Card.where.sort( r2: -1 )[0,10].all
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|