mongous 0.2.1 → 0.4.4

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/README.adoc +176 -26
  4. data/README.ja.adoc +176 -26
  5. data/Rakefile +8 -8
  6. data/_Gemfile.lock +38 -0
  7. data/lib/mongous/base.rb +52 -8
  8. data/lib/mongous/document.rb +21 -10
  9. data/lib/mongous/extention.rb +45 -35
  10. data/lib/mongous/filter.rb +316 -230
  11. data/lib/mongous/version.rb +1 -1
  12. data/mongous.gemspec +4 -4
  13. data/sample/connect_auto_0.rb +9 -0
  14. data/sample/declare_compact_1.rb +5 -8
  15. data/sample/declare_compact_2.rb +38 -0
  16. data/sample/declare_label_1.rb +7 -7
  17. data/sample/declare_ndex_1.rb +6 -6
  18. data/sample/declare_ndex_2.rb +7 -7
  19. data/sample/declare_strict_1.rb +2 -4
  20. data/sample/declare_strict_2.rb +2 -4
  21. data/sample/multi_collection_1.rb +0 -2
  22. data/sample/multi_collection_2.rb +0 -2
  23. data/sample/multi_collection_3.rb +24 -0
  24. data/sample/query_basic_1.rb +10 -4
  25. data/sample/query_basic_2.rb +10 -4
  26. data/sample/query_basic_3.rb +0 -2
  27. data/sample/query_basic_4.rb +0 -2
  28. data/sample/query_basic_5.rb +0 -2
  29. data/sample/query_basic_6.rb +56 -0
  30. data/sample/query_detail_1.rb +2 -3
  31. data/sample/query_detail_2.rb +2 -3
  32. data/sample/query_detail_3.rb +0 -2
  33. data/sample/query_filter_1.rb +0 -2
  34. data/sample/query_filter_2.rb +0 -2
  35. data/sample/query_find_1.rb +14 -13
  36. data/sample/query_select_1.rb +54 -0
  37. data/sample/query_skip_limit_1.rb +17 -16
  38. data/sample/query_skip_limit_2.rb +19 -10
  39. data/sample/query_sort_1.rb +43 -0
  40. data/sample/save_basic_1.rb +1 -5
  41. data/sample/save_basic_2.rb +1 -5
  42. data/sample/save_basic_3.rb +1 -5
  43. data/sample/save_detail_1.rb +0 -2
  44. data/sample/save_detail_2.rb +0 -2
  45. data/sample/save_detail_3.rb +5 -7
  46. data/sample/save_verify_1.rb +2 -4
  47. data/sample/save_verify_2.rb +0 -2
  48. data/sample/save_verify_3.rb +0 -2
  49. data/sample/save_verify_4.rb +0 -2
  50. data/sample/save_verify_5.rb +0 -2
  51. data/sample/save_verify_6.rb +0 -2
  52. data/sample/save_verify_7.rb +0 -2
  53. data/sample/update_basic_1.rb +1 -5
  54. data/sample/zap_basic_1.rb +1 -5
  55. data/sample/zap_basic_2.rb +2 -6
  56. data/sample/zap_basic_3.rb +7 -0
  57. data/sample/zbenchmark_search_1.rb +114 -0
  58. data/sample/zbenchmark_search_2.rb +114 -0
  59. data/sample/zbenchmark_search_3.rb +88 -0
  60. metadata +31 -22
  61. data/.travis.yml +0 -6
  62. data/sample/query_projection_1.rb +0 -41
  63. data/sample/query_sort_order_1.rb +0 -46
@@ -1,3 +1,3 @@
1
1
  module Mongous
2
- VERSION = "0.2.1"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -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 lightweight mongo wrapper library. }
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", "~> 2.13"
23
+ spec.add_runtime_dependency "mongo"
24
24
 
25
- spec.add_development_dependency "rake", "~> 12.0"
26
- spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
27
  end
@@ -0,0 +1,9 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.document! :Book
5
+
6
+ Book.each do |book|
7
+ p book
8
+ end
9
+
@@ -1,13 +1,10 @@
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
10
  book.author = "Alice"
@@ -16,13 +13,13 @@ book.style = "hardcover"
16
13
  book.size = "A4"
17
14
  book.price = 100
18
15
  book.page = 100
19
- # book.publish_at = nil # (default)
20
- # book.isbn = "978-3-16-148410-0"
16
+ book.isbn = "978-3-16-148410-0"
21
17
  # book.lang = nil # (default)
18
+ # book.created_at = nil # (created)
19
+ # book.updated_at = nil # (updated)
22
20
  book.save
23
21
 
24
-
25
- Book.each do |book|
26
- pp book
22
+ Book.each do |a_book|
23
+ pp a_book
27
24
  end
28
25
 
@@ -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 |a_book|
15
+ pp a_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 |a_book|
33
+ pp a_book
34
+ end
35
+ puts
36
+
37
+ Book2.drop
38
+
@@ -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
 
@@ -13,9 +11,10 @@ class Book
13
11
  field :size
14
12
  field :price
15
13
  field :page
16
- field :publish_at
17
14
  field :isbn
18
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
19
18
 
20
19
  verify :strict
21
20
  end
@@ -29,13 +28,14 @@ book.style = "softcover"
29
28
  book.size = "A5"
30
29
  book.price = 200
31
30
  book.page = 200
32
- # book.publish_at = nil # (default)
33
- # book.isbn = "978-3-16-148410-0"
31
+ book.isbn = "978-3-16-148410-0"
34
32
  # book.lang = nil # (default)
33
+ # book.created_at = nil # (created)
34
+ # book.updated_at = nil # (updated)
35
35
  book.save
36
36
 
37
37
 
38
- Book.each do |book|
39
- pp book
38
+ Book.each do |a_book|
39
+ pp a_book
40
40
  end
41
41
 
@@ -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
 
@@ -13,9 +11,10 @@ class Book
13
11
  field :size
14
12
  field :price
15
13
  field :page
16
- field :publish_at
17
14
  field :isbn
18
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
19
18
 
20
19
  index :title
21
20
 
@@ -31,13 +30,14 @@ book.style = "paperback"
31
30
  book.size = "A6"
32
31
  book.price = 300
33
32
  book.page = 300
34
- # book.publish_at = nil # (default)
35
33
  book.isbn = "978-3-16-148410-0"
36
34
  # book.lang = nil # (default)
35
+ # book.created_at = nil # (created)
36
+ # book.updated_at = nil # (updated)
37
37
  book.save
38
38
 
39
39
 
40
- Book.each do |book|
41
- pp book
40
+ Book.each do |a_book|
41
+ pp a_book
42
42
  end
43
43
 
@@ -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
 
@@ -13,11 +11,12 @@ class Book
13
11
  field :size
14
12
  field :price
15
13
  field :page
16
- field :publish_at
17
14
  field :isbn
18
15
  field :lang
16
+ field :created_at
17
+ field :updated_at
19
18
 
20
- index :isbn, unique: true
19
+ index :isbn
21
20
 
22
21
  verify :strict
23
22
  end
@@ -31,13 +30,14 @@ book.style = "paperback"
31
30
  book.size = "A6"
32
31
  book.price = 300
33
32
  book.page = 300
34
- # book.publish_at = nil # (default)
35
33
  book.isbn = "978-3-16-148410-0"
36
34
  # book.lang = nil # (default)
35
+ # book.created_at = nil # (created)
36
+ # book.updated_at = nil # (updated)
37
37
  book.save
38
38
 
39
39
 
40
- Book.each do |book|
41
- pp book
40
+ Book.each do |a_book|
41
+ pp a_book
42
42
  end
43
43
 
@@ -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
 
@@ -45,7 +43,7 @@ book.isbn = "978-3-16-148410-0"
45
43
  book.save
46
44
 
47
45
 
48
- Book.each do |book|
49
- pp book
46
+ Book.each do |a_book|
47
+ pp a_book
50
48
  end
51
49
 
@@ -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
 
@@ -26,9 +24,9 @@ class Book
26
24
  end
27
25
 
28
26
 
29
- Book.each do |book|
27
+ Book.each do |a_book|
30
28
  begin
31
- pp book
29
+ pp a_book
32
30
  book.save # cause exception when detected violation.
33
31
  rescue => e
34
32
  p e.message
@@ -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
@@ -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
@@ -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
+
@@ -1,23 +1,29 @@
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
 
19
- Book.each do |book|
20
- p book
24
+ p "Book.each do |book|"
25
+ Book.each do |a_book|
26
+ p a_book
21
27
  end
22
28
  puts
23
29
 
@@ -1,23 +1,29 @@
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
 
19
- Book.where( title: /title/ ).each do |book|
20
- p book
24
+ p "Book.where( title: /title/ ).each do |book|"
25
+ Book.where( title: /title/ ).each do |a_book|
26
+ p a_book
21
27
  end
22
28
  puts
23
29
 
@@ -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
  end
@@ -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
  end
@@ -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
  end
@@ -0,0 +1,56 @@
1
+
2
+ # use new syntax from ruby 2.7
3
+
4
+ require "mongous"
5
+
6
+ Mongous.document! :Item
7
+
8
+ (0...10).each do |n|
9
+ unless Item.where( n: n ).first
10
+ Item.create( n: n, tag: [0x40 + n].pack("C") )
11
+ end
12
+ end
13
+ puts
14
+
15
+ p "Item.where( n: (2..5) ).select( _id: 0 ).each do |item|"
16
+ Item.where( n: (2..5) ).select( _id: 0 ).each do |item|
17
+ p item
18
+ end
19
+ puts
20
+
21
+ p "Item.where( n: (2...5) ).select( _id: 0 ).each do |item|"
22
+ Item.where( n: (2...5) ).select( _id: 0 ).each do |item|
23
+ p item
24
+ end
25
+ puts
26
+
27
+ p "Item.where( n: (..5) ).select( _id: 0 ).each do |item|"
28
+ Item.where( n: (..5) ).select( _id: 0 ).each do |item|
29
+ p item
30
+ end
31
+ puts
32
+
33
+ p "Item.where( n: (...5) ).select( _id: 0 ).each do |item|"
34
+ Item.where( n: (...5) ).select( _id: 0 ).each do |item|
35
+ p item
36
+ end
37
+ puts
38
+
39
+ p "Item.where( n: (2..) ).select( _id: 0 ).each do |item|"
40
+ Item.where( n: (2..) ).select( _id: 0 ).each do |item|
41
+ p item
42
+ end
43
+ puts
44
+
45
+ p "Item.not( n: (..2) ).select( _id: 0 ).each do |item|"
46
+ Item.not( n: (..2) ).select( _id: 0 ).each do |item|
47
+ p item
48
+ end
49
+ puts
50
+
51
+ p "Item.select( _id: 0 ).not( n: (..2) ).each do |item|"
52
+ Item.select( _id: 0 ).not( n: (..2) ).each do |item|
53
+ p item
54
+ end
55
+ puts
56
+