mongous 0.1.3 → 0.2.0
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 +142 -27
- data/README.ja.adoc +140 -25
- data/lib/mongous/document.rb +50 -27
- data/lib/mongous/extention.rb +56 -45
- data/lib/mongous/filter.rb +76 -57
- data/lib/mongous/version.rb +1 -1
- data/mongous.gemspec +3 -2
- 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 +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 +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_3.rb +3 -2
- 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 +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 +15 -14
- 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/lib/mongous/version.rb
CHANGED
data/mongous.gemspec
CHANGED
@@ -3,12 +3,13 @@ require_relative 'lib/mongous/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "mongous"
|
5
5
|
spec.version = Mongous::VERSION
|
6
|
-
spec.authors = ["
|
6
|
+
spec.authors = ["arimay"]
|
7
7
|
spec.email = ["arima.yasuhiro@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{ Mongo wrapper library. }
|
10
10
|
spec.description = %q{ Yet another lightweight mongo wrapper library. }
|
11
|
-
spec.
|
11
|
+
spec.homepage = "https://github.com/arimay/mongous"
|
12
|
+
spec.license = "MIT"
|
12
13
|
|
13
14
|
# Specify which files should be added to the gem when it is released.
|
14
15
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
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
data/sample/declare_label_1.rb
CHANGED
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,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( 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,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, style: "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( 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
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
class Book
|
7
|
+
include Mongous::Document
|
8
|
+
end
|
9
|
+
|
10
|
+
p book = Book.find.first
|
11
|
+
puts
|
12
|
+
|
13
|
+
Book.find.each do |book|
|
14
|
+
p book
|
15
|
+
end
|
16
|
+
puts
|
17
|
+
|
18
|
+
Book.find( title: /title/ ).each do |book|
|
19
|
+
p book
|
20
|
+
end
|
21
|
+
puts
|
22
|
+
|
23
|
+
Book.find( {}, { projection: {_id: 0} } ).each do |book|
|
24
|
+
p book
|
25
|
+
end
|
26
|
+
puts
|
27
|
+
|
28
|
+
Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
|
29
|
+
p book
|
30
|
+
end
|
31
|
+
|
@@ -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
|