mongous 0.2.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -0
- data/README.adoc +191 -38
- data/README.ja.adoc +192 -39
- data/Rakefile +8 -8
- data/lib/mongous/base.rb +52 -8
- data/lib/mongous/document.rb +36 -13
- data/lib/mongous/extention.rb +51 -39
- data/lib/mongous/filter.rb +316 -227
- data/lib/mongous/version.rb +1 -1
- data/mongous.gemspec +4 -4
- data/sample/connect_auto_0.rb +9 -0
- data/sample/declare_compact_1.rb +6 -8
- data/sample/declare_compact_2.rb +38 -0
- data/sample/declare_label_1.rb +9 -7
- data/sample/declare_ndex_1.rb +8 -6
- data/sample/declare_ndex_2.rb +9 -7
- data/sample/declare_strict_1.rb +9 -9
- data/sample/declare_strict_2.rb +4 -5
- data/sample/multi_collection_1.rb +0 -2
- data/sample/multi_collection_2.rb +5 -5
- data/sample/multi_collection_3.rb +24 -0
- data/sample/query_basic_1.rb +8 -2
- data/sample/query_basic_2.rb +8 -2
- data/sample/query_basic_3.rb +0 -2
- data/sample/query_basic_4.rb +3 -5
- data/sample/query_basic_5.rb +0 -2
- data/sample/query_basic_6.rb +56 -0
- data/sample/query_detail_1.rb +3 -3
- data/sample/query_detail_2.rb +3 -3
- data/sample/query_detail_3.rb +4 -5
- data/sample/query_filter_1.rb +1 -3
- data/sample/query_filter_2.rb +2 -4
- data/sample/query_find_1.rb +6 -5
- data/sample/query_select_1.rb +54 -0
- data/sample/query_skip_limit_1.rb +25 -14
- data/sample/query_skip_limit_2.rb +20 -11
- data/sample/query_sort_1.rb +43 -0
- data/sample/save_basic_1.rb +2 -6
- data/sample/save_basic_2.rb +2 -6
- data/sample/save_basic_3.rb +2 -6
- data/sample/save_detail_1.rb +3 -3
- data/sample/save_detail_2.rb +3 -3
- data/sample/save_detail_3.rb +10 -10
- data/sample/save_verify_1.rb +6 -6
- data/sample/save_verify_2.rb +0 -2
- data/sample/save_verify_3.rb +0 -2
- data/sample/save_verify_4.rb +0 -2
- data/sample/save_verify_5.rb +3 -5
- data/sample/save_verify_6.rb +3 -5
- data/sample/save_verify_7.rb +21 -0
- data/sample/update_basic_1.rb +9 -0
- data/sample/zap_basic_1.rb +1 -5
- data/sample/zap_basic_2.rb +2 -6
- data/sample/zap_basic_3.rb +2 -6
- data/sample/zbenchmark_search_1.rb +114 -0
- data/sample/zbenchmark_search_2.rb +114 -0
- data/sample/zbenchmark_search_3.rb +88 -0
- metadata +31 -21
- data/sample/query_projection_1.rb +0 -41
- data/sample/query_sort_order_1.rb +0 -46
data/lib/mongous/version.rb
CHANGED
data/mongous.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["arima.yasuhiro@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{ Mongo wrapper library. }
|
10
|
-
spec.description = %q{ Yet another
|
10
|
+
spec.description = %q{ Yet another mongo wrapper library. }
|
11
11
|
spec.homepage = "https://github.com/arimay/mongous"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "mongo"
|
23
|
+
spec.add_runtime_dependency "mongo"
|
24
24
|
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
27
|
end
|
data/sample/declare_compact_1.rb
CHANGED
@@ -1,26 +1,24 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
end
|
9
7
|
|
10
|
-
|
11
8
|
book = Book.new
|
12
9
|
book.title = "declare compact"
|
13
|
-
book.author = "
|
10
|
+
book.author = "Alice"
|
14
11
|
book.publisher = nil
|
15
|
-
book.style = "
|
12
|
+
book.style = "hardcover"
|
13
|
+
book.size = "A4"
|
16
14
|
book.price = 100
|
17
15
|
book.page = 100
|
18
|
-
|
19
|
-
# book.isbn = "978-3-16-148410-0"
|
16
|
+
book.isbn = "978-3-16-148410-0"
|
20
17
|
# book.lang = nil # (default)
|
18
|
+
# book.created_at = nil # (created)
|
19
|
+
# book.updated_at = nil # (updated)
|
21
20
|
book.save
|
22
21
|
|
23
|
-
|
24
22
|
Book.each do |book|
|
25
23
|
pp book
|
26
24
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.document! :Book1
|
5
|
+
|
6
|
+
book = Book1.new
|
7
|
+
book.title = "book1"
|
8
|
+
book.save
|
9
|
+
|
10
|
+
book = Book1.where( title: "book1" ).first
|
11
|
+
book.author = "alice"
|
12
|
+
book.save
|
13
|
+
|
14
|
+
Book1.each do |book|
|
15
|
+
pp book
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
|
19
|
+
Book1.drop
|
20
|
+
|
21
|
+
|
22
|
+
Mongous.document! :Book2, timestamp: true
|
23
|
+
|
24
|
+
book = Book2.new
|
25
|
+
book.title = "book2"
|
26
|
+
book.save
|
27
|
+
|
28
|
+
book = Book2.where( title: "book2" ).first
|
29
|
+
book.author = "bob"
|
30
|
+
book.save
|
31
|
+
|
32
|
+
Book2.each do |book|
|
33
|
+
pp book
|
34
|
+
end
|
35
|
+
puts
|
36
|
+
|
37
|
+
Book2.drop
|
38
|
+
|
data/sample/declare_label_1.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
|
@@ -10,11 +8,13 @@ class Book
|
|
10
8
|
field :author
|
11
9
|
field :publisher
|
12
10
|
field :style
|
11
|
+
field :size
|
13
12
|
field :price
|
14
13
|
field :page
|
15
|
-
field :publish_at
|
16
14
|
field :isbn
|
17
15
|
field :lang
|
16
|
+
field :created_at
|
17
|
+
field :updated_at
|
18
18
|
|
19
19
|
verify :strict
|
20
20
|
end
|
@@ -22,14 +22,16 @@ end
|
|
22
22
|
|
23
23
|
book = Book.new
|
24
24
|
book.title = "declare label"
|
25
|
-
book.author = "
|
25
|
+
book.author = "Bob"
|
26
26
|
book.publisher = nil
|
27
|
-
book.style = "
|
27
|
+
book.style = "softcover"
|
28
|
+
book.size = "A5"
|
28
29
|
book.price = 200
|
29
30
|
book.page = 200
|
30
|
-
|
31
|
-
# book.isbn = "978-3-16-148410-0"
|
31
|
+
book.isbn = "978-3-16-148410-0"
|
32
32
|
# book.lang = nil # (default)
|
33
|
+
# book.created_at = nil # (created)
|
34
|
+
# book.updated_at = nil # (updated)
|
33
35
|
book.save
|
34
36
|
|
35
37
|
|
data/sample/declare_ndex_1.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
|
@@ -10,11 +8,13 @@ class Book
|
|
10
8
|
field :author
|
11
9
|
field :publisher
|
12
10
|
field :style
|
11
|
+
field :size
|
13
12
|
field :price
|
14
13
|
field :page
|
15
|
-
field :publish_at
|
16
14
|
field :isbn
|
17
15
|
field :lang
|
16
|
+
field :created_at
|
17
|
+
field :updated_at
|
18
18
|
|
19
19
|
index :title
|
20
20
|
|
@@ -24,14 +24,16 @@ end
|
|
24
24
|
|
25
25
|
book = Book.new
|
26
26
|
book.title = "declare index 1"
|
27
|
-
book.author = "
|
27
|
+
book.author = "Candy"
|
28
28
|
book.publisher = nil
|
29
|
-
book.style = "
|
29
|
+
book.style = "paperback"
|
30
|
+
book.size = "A6"
|
30
31
|
book.price = 300
|
31
32
|
book.page = 300
|
32
|
-
# book.publish_at = nil # (default)
|
33
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_2.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
|
@@ -10,13 +8,15 @@ class Book
|
|
10
8
|
field :author
|
11
9
|
field :publisher
|
12
10
|
field :style
|
11
|
+
field :size
|
13
12
|
field :price
|
14
13
|
field :page
|
15
|
-
field :publish_at
|
16
14
|
field :isbn
|
17
15
|
field :lang
|
16
|
+
field :created_at
|
17
|
+
field :updated_at
|
18
18
|
|
19
|
-
index :isbn
|
19
|
+
index :isbn
|
20
20
|
|
21
21
|
verify :strict
|
22
22
|
end
|
@@ -24,14 +24,16 @@ end
|
|
24
24
|
|
25
25
|
book = Book.new
|
26
26
|
book.title = "declare index 2"
|
27
|
-
book.author = "
|
27
|
+
book.author = "Candy"
|
28
28
|
book.publisher = nil
|
29
|
-
book.style = "
|
29
|
+
book.style = "paperback"
|
30
|
+
book.size = "A6"
|
30
31
|
book.price = 300
|
31
32
|
book.page = 300
|
32
|
-
# book.publish_at = nil # (default)
|
33
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_strict_1.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
|
9
7
|
field :title, String, :must
|
10
8
|
field :author, String
|
11
9
|
field :publisher, String
|
12
|
-
field :style, String, %w[
|
10
|
+
field :style, String, %w[hardcover softcover paperback]
|
11
|
+
field :size, String, /[AB]\d/
|
13
12
|
field :price, Integer, (0..1_000_000)
|
14
13
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
14
|
field :isbn, String, proc{ isbn? }
|
16
15
|
field :lang, String, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
16
|
+
field :created_at, Time, create: proc{ Time.now }
|
17
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
18
|
|
20
19
|
verify :strict
|
21
20
|
verify { having?( title ) }
|
@@ -31,11 +30,12 @@ end
|
|
31
30
|
|
32
31
|
book = Book.new
|
33
32
|
book.title = "declare strict"
|
34
|
-
book.author = "
|
33
|
+
book.author = "David"
|
35
34
|
book.publisher = nil
|
36
|
-
book.style = "
|
37
|
-
book.
|
38
|
-
book.
|
35
|
+
book.style = "paperback"
|
36
|
+
book.size = "A7"
|
37
|
+
book.price = 400
|
38
|
+
book.page = 400
|
39
39
|
book.isbn = "978-3-16-148410-0"
|
40
40
|
# book.lang = nil # (default)
|
41
41
|
# book.created_at = nil # (create)
|
data/sample/declare_strict_2.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
|
9
7
|
field :title, String, :must
|
10
8
|
field :author, String
|
11
9
|
field :publisher, String, :must
|
12
|
-
field :style, String, %w[
|
10
|
+
field :style, String, %w[hardcover softcover paperback]
|
11
|
+
field :size, String, /[AB]\d/
|
13
12
|
field :price, Integer, (0..1_000_000)
|
14
13
|
field :page, Integer, proc{ page % 4 == 0 }
|
15
14
|
field :isbn, String, proc{ isbn? }
|
16
15
|
field :lang, String, default: "en"
|
17
|
-
field :created_at, Time, create:
|
18
|
-
field :updated_at, Time, update:
|
16
|
+
field :created_at, Time, create: proc{ Time.now }
|
17
|
+
field :updated_at, Time, update: proc{ Time.now }
|
19
18
|
|
20
19
|
verify :strict
|
21
20
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book1
|
7
5
|
include Mongous::Document
|
8
6
|
end
|
@@ -14,6 +12,7 @@ class Book2
|
|
14
12
|
field :author
|
15
13
|
field :publisher
|
16
14
|
field :style
|
15
|
+
field :size
|
17
16
|
field :price
|
18
17
|
field :page
|
19
18
|
field :isbn
|
@@ -30,13 +29,14 @@ class Book3
|
|
30
29
|
field :title, :must
|
31
30
|
field :author
|
32
31
|
field :publisher, String, :must
|
33
|
-
field :style, String, %w[
|
32
|
+
field :style, String, %w[hardcover softcover paperback]
|
33
|
+
field :size, String, /[AB]\d/
|
34
34
|
field :price, Integer, (0..1_000_000)
|
35
35
|
field :page, Integer, proc{ page > 0 }
|
36
36
|
field :isbn, proc{ isbn? }
|
37
37
|
field :lang, String, default: "en"
|
38
|
-
field :created_at, Time, create:
|
39
|
-
field :updated_at, Time, update:
|
38
|
+
field :created_at, Time, create: proc{ Time.now }
|
39
|
+
field :updated_at, Time, update: proc{ Time.now }
|
40
40
|
|
41
41
|
verify :strict
|
42
42
|
verify { having?( title ) }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.document! :Book1
|
5
|
+
Mongous.document! :Book2
|
6
|
+
Mongous.document! :Book3
|
7
|
+
|
8
|
+
pp Book1.collection
|
9
|
+
pp Book2.collection
|
10
|
+
pp Book3.collection
|
11
|
+
|
12
|
+
Mongous.document! :Book1
|
13
|
+
Mongous.document! :Book2, :Book3
|
14
|
+
|
15
|
+
pp Book1.collection
|
16
|
+
pp Book2.collection
|
17
|
+
pp Book3.collection
|
18
|
+
|
19
|
+
Mongous.document! :Book1, :Book2, :Book3
|
20
|
+
|
21
|
+
pp Book1.collection
|
22
|
+
pp Book2.collection
|
23
|
+
pp Book3.collection
|
24
|
+
|
data/sample/query_basic_1.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
end
|
9
7
|
|
8
|
+
p "book = Book.first"
|
10
9
|
p book = Book.first
|
11
10
|
puts
|
12
11
|
|
12
|
+
p "book = Book.last"
|
13
|
+
p book = Book.last
|
14
|
+
puts
|
15
|
+
|
16
|
+
p "count = Book.count"
|
13
17
|
p count = Book.count
|
14
18
|
puts
|
15
19
|
|
20
|
+
p "books = Book.all"
|
16
21
|
pp books = Book.all
|
17
22
|
puts
|
18
23
|
|
24
|
+
p "Book.each do |book|"
|
19
25
|
Book.each do |book|
|
20
26
|
p book
|
21
27
|
end
|
data/sample/query_basic_2.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
end
|
9
7
|
|
8
|
+
p "book = Book.where( title: /title/ ).first"
|
10
9
|
p book = Book.where( title: /title/ ).first
|
11
10
|
puts
|
12
11
|
|
12
|
+
p "book = Book.where( title: /title/ ).last"
|
13
|
+
p book = Book.where( title: /title/ ).last
|
14
|
+
puts
|
15
|
+
|
16
|
+
p "count = Book.where( title: /title/ ).count"
|
13
17
|
p count = Book.where( title: /title/ ).count
|
14
18
|
puts
|
15
19
|
|
20
|
+
p "books = Book.where( title: /title/ ).all"
|
16
21
|
pp books = Book.where( title: /title/ ).all
|
17
22
|
puts
|
18
23
|
|
24
|
+
p "Book.where( title: /title/ ).each do |book|"
|
19
25
|
Book.where( title: /title/ ).each do |book|
|
20
26
|
p book
|
21
27
|
end
|