mongous 0.1.4 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +156 -37
- data/README.ja.adoc +155 -36
- data/lib/mongous/document.rb +66 -31
- data/lib/mongous/extention.rb +59 -46
- data/lib/mongous/filter.rb +82 -60
- data/lib/mongous/version.rb +1 -1
- 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 +4 -3
- data/sample/declare_label_1.rb +5 -3
- data/sample/declare_ndex_1.rb +5 -3
- data/sample/declare_ndex_2.rb +5 -3
- 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/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 +1 -0
- data/sample/query_detail_2.rb +1 -0
- data/sample/query_detail_3.rb +5 -3
- 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 +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 +10 -7
- 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
- metadata +12 -11
- 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
- data/sample/zap_basic_3.rb +0 -11
data/lib/mongous/version.rb
CHANGED
data/sample/connect_auto_2.rb
CHANGED
data/sample/connect_default_2.rb
CHANGED
data/sample/connect_environ_2.rb
CHANGED
data/sample/declare_compact_1.rb
CHANGED
@@ -9,10 +9,11 @@ end
|
|
9
9
|
|
10
10
|
|
11
11
|
book = Book.new
|
12
|
-
book.title = "
|
13
|
-
book.author = "
|
12
|
+
book.title = "declare compact"
|
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
|
@@ -21,10 +22,11 @@ end
|
|
21
22
|
|
22
23
|
|
23
24
|
book = Book.new
|
24
|
-
book.title = "
|
25
|
-
book.author = "
|
25
|
+
book.title = "declare label"
|
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
|
@@ -23,10 +24,11 @@ end
|
|
23
24
|
|
24
25
|
|
25
26
|
book = Book.new
|
26
|
-
book.title = "
|
27
|
-
book.author = "
|
27
|
+
book.title = "declare index 1"
|
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
|
@@ -23,10 +24,11 @@ end
|
|
23
24
|
|
24
25
|
|
25
26
|
book = Book.new
|
26
|
-
book.title = "
|
27
|
-
book.author = "
|
27
|
+
book.title = "declare index 2"
|
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,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, %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
|
-
field :publish_at, Date, &proc{ Date.today }
|
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 ) }
|
@@ -23,21 +25,23 @@ class Book
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def isbn?
|
26
|
-
isbn
|
28
|
+
isbn.gsub(/\D*/, '').size == 13
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
32
|
|
31
33
|
book = Book.new
|
32
|
-
book.title = "
|
33
|
-
book.author = "
|
34
|
+
book.title = "declare strict"
|
35
|
+
book.author = "David"
|
34
36
|
book.publisher = nil
|
35
|
-
book.style = "
|
36
|
-
book.
|
37
|
-
book.
|
38
|
-
|
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)
|
43
|
+
# book.created_at = nil # (create)
|
44
|
+
# book.updated_at = nil # (update)
|
41
45
|
book.save
|
42
46
|
|
43
47
|
|
data/sample/declare_strict_2.rb
CHANGED
@@ -9,12 +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
|
-
field :publish_at, Date, &proc{ Date.today }
|
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
|
|
File without changes
|
@@ -0,0 +1,63 @@
|
|
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 :author
|
15
|
+
field :publisher
|
16
|
+
field :style
|
17
|
+
field :size
|
18
|
+
field :price
|
19
|
+
field :page
|
20
|
+
field :isbn
|
21
|
+
field :lang
|
22
|
+
field :created_at
|
23
|
+
field :updated_at
|
24
|
+
|
25
|
+
verify :strict
|
26
|
+
end
|
27
|
+
|
28
|
+
class Book3
|
29
|
+
include Mongous::Document
|
30
|
+
|
31
|
+
field :title, :must
|
32
|
+
field :author
|
33
|
+
field :publisher, String, :must
|
34
|
+
field :style, String, %w[hardcover softcover paperback]
|
35
|
+
field :size, String, /[AB]\d/
|
36
|
+
field :price, Integer, (0..1_000_000)
|
37
|
+
field :page, Integer, proc{ page > 0 }
|
38
|
+
field :isbn, proc{ isbn? }
|
39
|
+
field :lang, String, default: "en"
|
40
|
+
field :created_at, Time, create: proc{ Time.now }
|
41
|
+
field :updated_at, Time, update: proc{ Time.now }
|
42
|
+
|
43
|
+
verify :strict
|
44
|
+
verify { having?( title ) }
|
45
|
+
verify do
|
46
|
+
having?( author ) | having?( publisher )
|
47
|
+
end
|
48
|
+
|
49
|
+
def isbn?
|
50
|
+
isbn.gsub(/[\D]*/, '').size == 13
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
pp Book1.fields
|
56
|
+
puts
|
57
|
+
|
58
|
+
pp Book2.fields
|
59
|
+
puts
|
60
|
+
|
61
|
+
pp Book3.fields
|
62
|
+
puts
|
63
|
+
|
data/sample/query_basic_1.rb
CHANGED
data/sample/query_basic_2.rb
CHANGED
@@ -7,14 +7,16 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
+
p book = Book.where( title: /title/ ).first
|
11
|
+
puts
|
10
12
|
|
11
|
-
p
|
13
|
+
p count = Book.where( title: /title/ ).count
|
12
14
|
puts
|
13
15
|
|
14
|
-
pp books = Book.
|
16
|
+
pp books = Book.where( title: /title/ ).all
|
15
17
|
puts
|
16
18
|
|
17
|
-
Book.
|
19
|
+
Book.where( title: /title/ ).each do |book|
|
18
20
|
p book
|
19
21
|
end
|
20
22
|
puts
|
data/sample/query_basic_3.rb
CHANGED
@@ -7,13 +7,12 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
Book.filter.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
|
10
|
+
Book.where.option( projection: {_id: 0, title: 1, author: 1} ).each do |book|
|
12
11
|
p book
|
13
12
|
end
|
14
13
|
puts
|
15
14
|
|
16
|
-
Book.
|
15
|
+
Book.where( title: /title/ ).option( projection: {_id: 0, title: 1} ).each do |book|
|
17
16
|
p book
|
18
17
|
end
|
19
18
|
|
data/sample/query_basic_4.rb
CHANGED
@@ -7,18 +7,17 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
Book.filter( style: %w[A4 A5 A6] ).each do |book|
|
10
|
+
Book.where( size: %w[A4 A5 A6] ).each do |book|
|
12
11
|
p book
|
13
12
|
end
|
14
13
|
puts
|
15
14
|
|
16
|
-
Book.
|
15
|
+
Book.where( size: %w[A4 A5]).each do |book|
|
17
16
|
p book
|
18
17
|
end
|
19
18
|
puts
|
20
19
|
|
21
|
-
Book.
|
20
|
+
Book.where( size: %w[A5] ).each do |book|
|
22
21
|
p book
|
23
22
|
end
|
24
23
|
puts
|
data/sample/query_basic_5.rb
CHANGED
@@ -7,13 +7,12 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
Book.filter( page: (100..300) ).each do |book|
|
10
|
+
Book.where( page: (100..300) ).each do |book|
|
12
11
|
p book
|
13
12
|
end
|
14
13
|
puts
|
15
14
|
|
16
|
-
Book.
|
15
|
+
Book.where( page: (100...300) ).each do |book|
|
17
16
|
p book
|
18
17
|
end
|
19
18
|
puts
|
data/sample/query_detail_1.rb
CHANGED
data/sample/query_detail_2.rb
CHANGED
data/sample/query_detail_3.rb
CHANGED
@@ -9,12 +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
|
-
field :publish_at, Date, &proc{ Date.today }
|
16
16
|
field :isbn, proc{ isbn? }
|
17
|
-
field :lang,
|
17
|
+
field :lang, 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
|
|
@@ -7,12 +7,15 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
Book.
|
12
|
-
Book.
|
10
|
+
(1..3).each do |n|
|
11
|
+
unless Book.where( title: "complex #{n}" ).first
|
12
|
+
Book.create( title: "complex #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts
|
13
16
|
|
14
|
-
filter1 = Book.
|
15
|
-
filter2 = Book.not(
|
17
|
+
filter1 = Book.where( title: /comp/ )
|
18
|
+
filter2 = Book.not( price: (2000...3000) )
|
16
19
|
filter3 = Book.and( filter1, filter2 ).select( _id: 0 )
|
17
20
|
filter4 = Book.or( filter1, filter2 ).select( _id: 0 )
|
18
21
|
p filter1.to_condition
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
class Book
|
7
|
+
include Mongous::Document
|
8
|
+
|
9
|
+
filter :title1, { title: /filter/ }
|
10
|
+
filter :price1, { price: (2000..3000) }
|
11
|
+
filter :page1, where( size: %w[A3 A4] )
|
12
|
+
end
|
13
|
+
|
14
|
+
(1..5).each do |n|
|
15
|
+
unless Book.where( title: "filter #{n}" ).first
|
16
|
+
Book.create( title: "filter #{n}", author: (0x40 + n).chr, size: "A#{n + 3}", price: n * 1000, page: n * 100 )
|
17
|
+
end
|
18
|
+
end
|
19
|
+
puts
|
20
|
+
|
21
|
+
filter1 = Book.where( :price1 )
|
22
|
+
filter2 = Book.not( :page1 )
|
23
|
+
filter3 = Book.and( :title1, filter1, filter2 ).select( _id: 0 )
|
24
|
+
filter4 = Book.and( :title1, Book.or( filter1, filter2 ) ).select( _id: 0 )
|
25
|
+
p filter1.to_condition
|
26
|
+
p filter2.to_condition
|
27
|
+
p filter3.to_condition
|
28
|
+
p filter4.to_condition
|
29
|
+
puts
|
30
|
+
|
31
|
+
filter1.each do |book|
|
32
|
+
p book
|
33
|
+
end
|
34
|
+
puts
|
35
|
+
|
36
|
+
filter2.each do |book|
|
37
|
+
p book
|
38
|
+
end
|
39
|
+
puts
|
40
|
+
|
41
|
+
filter3.each do |book|
|
42
|
+
p book
|
43
|
+
end
|
44
|
+
puts
|
45
|
+
|
46
|
+
filter4.each do |book|
|
47
|
+
p book
|
48
|
+
end
|
49
|
+
puts
|
50
|
+
|