mongous 0.1.8 → 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 +115 -30
- data/README.ja.adoc +115 -30
- data/lib/mongous/document.rb +50 -27
- data/lib/mongous/extention.rb +50 -43
- data/lib/mongous/filter.rb +45 -51
- data/lib/mongous/version.rb +1 -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 +0 -1
- data/sample/query_basic_2.rb +4 -5
- 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} +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_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 +10 -11
- data/sample/multi_docs_2.rb +0 -58
- data/sample/query_basic_7.rb +0 -38
- data/sample/query_limit_1.rb +0 -44
- data/sample/query_order_1.rb +0 -49
- data/sample/template_article.rb +0 -5
- data/sample/template_person.rb +0 -12
data/sample/declare_ndex_1.rb
CHANGED
data/sample/declare_ndex_2.rb
CHANGED
data/sample/declare_strict_1.rb
CHANGED
@@ -12,9 +12,10 @@ class Book
|
|
12
12
|
field :style, String, %w[A4 A5 A6]
|
13
13
|
field :price, Integer, (0..1_000_000)
|
14
14
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
|
-
field :publish_at, Date, &proc{ Date.today }
|
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 ) }
|
@@ -23,21 +24,22 @@ class Book
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def isbn?
|
26
|
-
isbn
|
27
|
+
isbn.gsub(/\D*/, '').size == 13
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
|
31
32
|
book = Book.new
|
32
|
-
book.title = "
|
33
|
+
book.title = "declare strict"
|
33
34
|
book.author = "foobar"
|
34
35
|
book.publisher = nil
|
35
36
|
book.style = "A6"
|
36
37
|
book.price = 300
|
37
38
|
book.page = 300
|
38
|
-
# book.publish_at = nil # (default)
|
39
39
|
book.isbn = "978-3-16-148410-0"
|
40
40
|
# book.lang = nil # (default)
|
41
|
+
# book.created_at = nil # (create)
|
42
|
+
# book.updated_at = nil # (update)
|
41
43
|
book.save
|
42
44
|
|
43
45
|
|
data/sample/declare_strict_2.rb
CHANGED
@@ -12,9 +12,10 @@ class Book
|
|
12
12
|
field :style, String, %w[A4 A5 A6]
|
13
13
|
field :price, Integer, (0..1_000_000)
|
14
14
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
|
-
field :publish_at, Date, &proc{ Date.today }
|
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
|
|
File without changes
|
@@ -0,0 +1,61 @@
|
|
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 :price
|
18
|
+
field :page
|
19
|
+
field :isbn
|
20
|
+
field :lang
|
21
|
+
field :created_at
|
22
|
+
field :updated_at
|
23
|
+
|
24
|
+
verify :strict
|
25
|
+
end
|
26
|
+
|
27
|
+
class Book3
|
28
|
+
include Mongous::Document
|
29
|
+
|
30
|
+
field :title, :must
|
31
|
+
field :author
|
32
|
+
field :publisher, String, :must
|
33
|
+
field :style, String, %w[A4 A5 A6]
|
34
|
+
field :price, Integer, (0..1_000_000)
|
35
|
+
field :page, Integer, proc{ page > 0 }
|
36
|
+
field :isbn, proc{ isbn? }
|
37
|
+
field :lang, String, default: "en"
|
38
|
+
field :created_at, Time, create: ->(){ Time.now }
|
39
|
+
field :updated_at, Time, update: ->(){ Time.now }
|
40
|
+
|
41
|
+
verify :strict
|
42
|
+
verify { having?( title ) }
|
43
|
+
verify do
|
44
|
+
having?( author ) | having?( publisher )
|
45
|
+
end
|
46
|
+
|
47
|
+
def isbn?
|
48
|
+
isbn.gsub(/[\D]*/, '').size == 13
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
pp Book1.fields
|
54
|
+
puts
|
55
|
+
|
56
|
+
pp Book2.fields
|
57
|
+
puts
|
58
|
+
|
59
|
+
pp Book3.fields
|
60
|
+
puts
|
61
|
+
|
data/sample/query_basic_1.rb
CHANGED
data/sample/query_basic_2.rb
CHANGED
@@ -7,17 +7,16 @@ class Book
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
p book = Book.filter( title: /title/ ).first
|
10
|
+
p book = Book.where( title: /title/ ).first
|
12
11
|
puts
|
13
12
|
|
14
|
-
p count = Book.
|
13
|
+
p count = Book.where( title: /title/ ).count
|
15
14
|
puts
|
16
15
|
|
17
|
-
pp books = Book.
|
16
|
+
pp books = Book.where( title: /title/ ).all
|
18
17
|
puts
|
19
18
|
|
20
|
-
Book.
|
19
|
+
Book.where( title: /title/ ).each do |book|
|
21
20
|
p book
|
22
21
|
end
|
23
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( style: %w[A4 A5 A6] ).each do |book|
|
12
11
|
p book
|
13
12
|
end
|
14
13
|
puts
|
15
14
|
|
16
|
-
Book.
|
15
|
+
Book.where( style: %w[A4 A5]).each do |book|
|
17
16
|
p book
|
18
17
|
end
|
19
18
|
puts
|
20
19
|
|
21
|
-
Book.
|
20
|
+
Book.where( style: %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_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
|
|
@@ -7,11 +7,14 @@ 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, style: "A#{n + 3}", price: n * 1000, page: n * 100 )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
puts
|
13
16
|
|
14
|
-
filter1 = Book.
|
17
|
+
filter1 = Book.where( title: /comp/ )
|
15
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 )
|
@@ -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( style: %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, style: "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
|
+
|
@@ -7,11 +7,8 @@ class Label
|
|
7
7
|
include Mongous::Document
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
10
|
(0...10).each do |n|
|
12
|
-
|
13
|
-
label
|
14
|
-
else
|
11
|
+
unless Label.where( n: n ).first
|
15
12
|
Label.create( n: n, tag: [0x40 + n].pack("C") )
|
16
13
|
end
|
17
14
|
end
|
@@ -22,22 +19,22 @@ Label.each do |label|
|
|
22
19
|
end
|
23
20
|
puts
|
24
21
|
|
25
|
-
Label.
|
22
|
+
Label.where.projection( tag: 1 ).each do |label|
|
26
23
|
p label
|
27
24
|
end
|
28
25
|
puts
|
29
26
|
|
30
|
-
Label.
|
27
|
+
Label.where.projection( _id: 0, n: 1 ).each do |label|
|
31
28
|
p label
|
32
29
|
end
|
33
30
|
puts
|
34
31
|
|
35
|
-
Label.
|
32
|
+
Label.where.select( _id: 0, n: 1, tag: 1 ).each do |label|
|
36
33
|
p label
|
37
34
|
end
|
38
35
|
puts
|
39
36
|
|
40
|
-
Label.
|
37
|
+
Label.where( n: [0,2,4,6,8] ).select( _id: 0, n: 1, tag: 1 ).each do |label|
|
41
38
|
p label
|
42
39
|
end
|
43
40
|
puts
|
@@ -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
|
+
|