mongous 0.3.0 → 0.4.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.
@@ -1,3 +1,3 @@
1
1
  module Mongous
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
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
 
@@ -0,0 +1,9 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.attach! :Book
5
+
6
+ Book.each do |book|
7
+ p book
8
+ end
9
+
@@ -19,22 +19,32 @@ Label.each do |label|
19
19
  end
20
20
  puts
21
21
 
22
- Label.where.projection( tag: 1 ).each do |label|
22
+ Label.select( tag: 1 ).each do |label|
23
23
  p label
24
24
  end
25
25
  puts
26
26
 
27
- Label.where.projection( _id: 0, n: 1 ).each do |label|
27
+ Label.select( :tag ).each do |label|
28
28
  p label
29
29
  end
30
30
  puts
31
31
 
32
- Label.where.select( _id: 0, n: 1, tag: 1 ).each do |label|
32
+ Label.select( _id: 0, n: 1 ).each do |label|
33
33
  p label
34
34
  end
35
35
  puts
36
36
 
37
- Label.where( n: [0,2,4,6,8] ).select( _id: 0, n: 1, tag: 1 ).each do |label|
37
+ Label.select( n: 1, tag: 1 ).each do |label|
38
+ p label
39
+ end
40
+ puts
41
+
42
+ Label.select( :n, :tag ).each do |label|
43
+ p label
44
+ end
45
+ puts
46
+
47
+ Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|
38
48
  p label
39
49
  end
40
50
  puts
@@ -0,0 +1,90 @@
1
+
2
+ require "mongous"
3
+
4
+ Mongous.connect!
5
+
6
+ class Card
7
+ include Mongous::Document
8
+ field :i1, Integer
9
+ field :i2, Integer
10
+ field :f1, Float
11
+ field :f2, Float
12
+ field :s1, String
13
+ field :s2, String
14
+ field :d1, Date
15
+ field :d2, Date
16
+ field :t1, Time
17
+ field :t2, Time
18
+ field :r1, Float
19
+ field :r2, Float
20
+
21
+ index :i2, unique: true
22
+ index :f2, unique: true
23
+ index :s2, unique: true
24
+ index :d2, unique: true
25
+ index :t2, unique: true
26
+ index :r2
27
+ end
28
+
29
+ require "benchmark"
30
+ require "date"
31
+
32
+ COUNT = 100000
33
+
34
+ D0 = Date.parse( "2020-01-01" )
35
+ T0 = D0.to_time
36
+
37
+ Benchmark.bm 40 do |r|
38
+ if COUNT != Card.count
39
+ Card.delete
40
+ r.report "create #{COUNT}" do
41
+ (0...COUNT).each do |i|
42
+ f = i.to_f
43
+ s = i.to_s
44
+ d = D0 + i
45
+ t = T0 + i
46
+ rn = rand
47
+ card = Card.create(
48
+ i1: i,
49
+ i2: i,
50
+ f1: f,
51
+ f2: f,
52
+ s1: s,
53
+ s2: s,
54
+ d1: d,
55
+ d2: d,
56
+ t1: t,
57
+ t2: t,
58
+ r1: rn,
59
+ r2: rn,
60
+ )
61
+ end
62
+ end
63
+ end
64
+
65
+ r.report "first, order by asc without index" do
66
+ Card.where.sort( r1: 1 ).first
67
+ end
68
+ r.report "first, order by desc without index" do
69
+ Card.where.sort( r1: -1 ).first
70
+ end
71
+ r.report "top 10, order by asc without index" do
72
+ Card.where.sort( r1: 1 )[0,10].all
73
+ end
74
+ r.report "top 10, order by desc without index" do
75
+ Card.where.sort( r1: -1 )[0,10].all
76
+ end
77
+ r.report "first, order by asc with index" do
78
+ Card.where.sort( r2: 1 ).first
79
+ end
80
+ r.report "first, order by desc with index" do
81
+ Card.where.sort( r2: -1 ).first
82
+ end
83
+ r.report "top 10, order by asc with index" do
84
+ Card.where.sort( r2: 1 )[0,10].all
85
+ end
86
+ r.report "top 10, order by desc with index" do
87
+ Card.where.sort( r2: -1 )[0,10].all
88
+ end
89
+ end
90
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongous
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arimay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: " Yet another lightweight mongo wrapper library. "
55
+ description: " Yet another mongo wrapper library. "
56
56
  email:
57
57
  - arima.yasuhiro@gmail.com
58
58
  executables: []
@@ -75,6 +75,7 @@ files:
75
75
  - lib/mongous/filter.rb
76
76
  - lib/mongous/version.rb
77
77
  - mongous.gemspec
78
+ - sample/connect_auto_0.rb
78
79
  - sample/connect_auto_1.rb
79
80
  - sample/connect_auto_2.rb
80
81
  - sample/connect_default_1.rb
@@ -104,7 +105,7 @@ files:
104
105
  - sample/query_filter_1.rb
105
106
  - sample/query_filter_2.rb
106
107
  - sample/query_find_1.rb
107
- - sample/query_projection_1.rb
108
+ - sample/query_select_1.rb
108
109
  - sample/query_skip_limit_1.rb
109
110
  - sample/query_skip_limit_2.rb
110
111
  - sample/query_sort_order_1.rb
@@ -127,6 +128,7 @@ files:
127
128
  - sample/zap_basic_3.rb
128
129
  - sample/zbenchmark_search_1.rb
129
130
  - sample/zbenchmark_search_2.rb
131
+ - sample/zbenchmark_search_3.rb
130
132
  homepage: https://github.com/arimay/mongous
131
133
  licenses:
132
134
  - MIT