mongous 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +16 -1
- data/README.ja.adoc +16 -1
- data/lib/mongous/extention.rb +2 -2
- data/lib/mongous/filter.rb +48 -23
- data/lib/mongous/version.rb +1 -1
- 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/query_basic_1.rb +3 -0
- data/sample/query_basic_2.rb +3 -0
- data/sample/query_basic_7.rb +38 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ac08d4dc3cd1b50de8ae75c4db5f63b9604abefa5890f046564d44619d75cf4
|
4
|
+
data.tar.gz: 446aae2fcd699ad4a27cc5f15790a00d84eaceff3e38ef4ded3b5aec425dcba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0e4ff3b90f13ac1bdb328ecac4c8986120e780575dbb97a242638d2cfd2c11581963cc2141c2f09f3a184cdcef85420354f4a12d02eca890c66b1458c9ea8e
|
7
|
+
data.tar.gz: 6e78c1a620e8cdc974e9e60bca01f54b0127b225a7e1e0f567c7354ec7d43adf1cd2e3ffa72859f6805ffcacd8b3a198258763a4f14ab0f216b6f4d585d56e0d
|
data/README.adoc
CHANGED
@@ -128,9 +128,11 @@ Book.or( filter1, filter3 ).each do |book|
|
|
128
128
|
p book
|
129
129
|
end
|
130
130
|
|
131
|
-
Book.find( {}, { projection: {_id: 0} } ).each do |book|
|
131
|
+
Book.find( { title: /title/ }, { projection: {_id: 0} } ).each do |book|
|
132
132
|
p book
|
133
133
|
end
|
134
|
+
|
135
|
+
pp Book.filter( title: /title/ )[0, 5].all
|
134
136
|
----
|
135
137
|
|
136
138
|
=== Update document
|
@@ -187,6 +189,19 @@ Mongous.connect( hosts_or_uri = nil, **opts )
|
|
187
189
|
include Mongous::Document
|
188
190
|
----
|
189
191
|
|
192
|
+
=== Bind another database.
|
193
|
+
|
194
|
+
[source,ruby]
|
195
|
+
----
|
196
|
+
set_client( client )
|
197
|
+
----
|
198
|
+
|
199
|
+
* Result:
|
200
|
+
** nil.
|
201
|
+
|
202
|
+
* Parameter:
|
203
|
+
** client: Mongo::Client instance.
|
204
|
+
|
190
205
|
=== Declare document structure.
|
191
206
|
|
192
207
|
[source,ruby]
|
data/README.ja.adoc
CHANGED
@@ -128,9 +128,11 @@ Book.or( filter1, filter3 ).each do |book|
|
|
128
128
|
p book
|
129
129
|
end
|
130
130
|
|
131
|
-
Book.find( {}, { projection: {_id: 0} } ).each do |book|
|
131
|
+
Book.find( { title: /title/ }, { projection: {_id: 0} } ).each do |book|
|
132
132
|
p book
|
133
133
|
end
|
134
|
+
|
135
|
+
pp Book.filter( title: /title/ )[0, 5].all
|
134
136
|
----
|
135
137
|
|
136
138
|
=== ドキュメント更新
|
@@ -187,6 +189,19 @@ Mongous.connect( hosts_or_uri = nil, **opts )
|
|
187
189
|
include Mongous::Document
|
188
190
|
----
|
189
191
|
|
192
|
+
=== 別のデータベースを割り当てる.
|
193
|
+
|
194
|
+
[source,ruby]
|
195
|
+
----
|
196
|
+
set_client( client )
|
197
|
+
----
|
198
|
+
|
199
|
+
* Result:
|
200
|
+
** nil.
|
201
|
+
|
202
|
+
* Parameter:
|
203
|
+
** client: Mongo::Client instance.
|
204
|
+
|
190
205
|
=== ドキュメントの要素を定義する.
|
191
206
|
|
192
207
|
[source,ruby]
|
data/lib/mongous/extention.rb
CHANGED
@@ -10,7 +10,7 @@ module Mongous
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def client=( _client )
|
14
14
|
m = /(.*?):(\d+)/.match( caller()[0] )
|
15
15
|
call_from = [ m[1], m[2] ].join(":")
|
16
16
|
if !_client.is_a?( Mongo::Client )
|
@@ -28,7 +28,7 @@ module Mongous
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def collection_name=( _collection_name )
|
32
32
|
self.class_variable_set( :@@collection_name, _collection_name )
|
33
33
|
if self.class_variable_defined?( :@@collection )
|
34
34
|
self.remove_class_variable( :@@collection )
|
data/lib/mongous/filter.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
|
2
2
|
module Mongous
|
3
3
|
module Extention
|
4
|
+
def count
|
5
|
+
self.collection.find.count
|
6
|
+
end
|
7
|
+
|
4
8
|
def first
|
5
9
|
doc = self.collection.find.first
|
6
10
|
self.new( **doc ) if doc
|
@@ -126,51 +130,59 @@ module Mongous
|
|
126
130
|
end
|
127
131
|
|
128
132
|
def option( _option )
|
129
|
-
self.option!( _option )
|
130
|
-
self.dup
|
131
|
-
end
|
132
|
-
|
133
|
-
def option!( _option )
|
134
133
|
@option.merge!( _option )
|
134
|
+
self.dup
|
135
135
|
end
|
136
136
|
|
137
137
|
def projection( _projection )
|
138
|
-
|
138
|
+
@projection = _projection
|
139
139
|
self.dup
|
140
140
|
end
|
141
141
|
alias :select :projection
|
142
142
|
|
143
|
-
def projection!( _projection )
|
144
|
-
@projection = _projection
|
145
|
-
end
|
146
|
-
|
147
143
|
def sort( _sort )
|
148
|
-
|
144
|
+
@sort = _sort
|
149
145
|
self.dup
|
150
146
|
end
|
151
147
|
alias :order :sort
|
152
148
|
|
153
|
-
def sort!( _sort )
|
154
|
-
@sort = _sort
|
155
|
-
end
|
156
|
-
|
157
149
|
def skip( _skip )
|
158
|
-
|
150
|
+
@skip = _skip
|
159
151
|
self.dup
|
160
152
|
end
|
161
153
|
alias :offset :skip
|
162
154
|
|
163
|
-
def skip!( _skip )
|
164
|
-
@skip = _skip
|
165
|
-
end
|
166
|
-
|
167
155
|
def limit( _limit )
|
168
|
-
|
156
|
+
@limit = _limit
|
169
157
|
self.dup
|
170
158
|
end
|
171
159
|
|
172
|
-
def
|
173
|
-
|
160
|
+
def []( nth_or_range, len = 1 )
|
161
|
+
case nth_or_range
|
162
|
+
when Integer
|
163
|
+
raise Mongous::Error, "invalid nth. : #{ nth_or_range }" if len < 0
|
164
|
+
@skip = nth_or_range
|
165
|
+
|
166
|
+
raise Mongous::Error, "invalid len. : #{ len }" if !len.is_a? Integer || len <= 0
|
167
|
+
@limit = len
|
168
|
+
|
169
|
+
when Range
|
170
|
+
from = nth_or_range.begin
|
171
|
+
raise Mongous::Error, "invalid range. : #{ nth_or_range }" unless from.is_a? Integer
|
172
|
+
|
173
|
+
to = nth_or_range.end
|
174
|
+
raise Mongous::Error, "invalid range. : #{ nth_or_range }" unless to.is_a? Integer
|
175
|
+
|
176
|
+
to -= 1 if nth_or_range.exclude_end?
|
177
|
+
@skip = from
|
178
|
+
@limit = to - from + 1
|
179
|
+
|
180
|
+
else
|
181
|
+
raise Mongous::Error, "invalid class. : #{ nth_or_range }"
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
self.dup
|
174
186
|
end
|
175
187
|
|
176
188
|
def do_find
|
@@ -184,6 +196,19 @@ module Mongous
|
|
184
196
|
found
|
185
197
|
end
|
186
198
|
|
199
|
+
def count
|
200
|
+
_count = do_find.count
|
201
|
+
if @skip && @limit
|
202
|
+
[_count - @skip, @limit].min
|
203
|
+
elsif @skip.nil? && @limit
|
204
|
+
[_count, @limit].min
|
205
|
+
elsif @skip && @limit.nil?
|
206
|
+
[_count - @skip, 0].max
|
207
|
+
else
|
208
|
+
_count
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
187
212
|
def first
|
188
213
|
doc = do_find.first
|
189
214
|
@klass.new( **doc ) if doc
|
data/lib/mongous/version.rb
CHANGED
data/sample/connect_auto_2.rb
CHANGED
data/sample/connect_default_2.rb
CHANGED
data/sample/connect_environ_2.rb
CHANGED
data/sample/query_basic_1.rb
CHANGED
data/sample/query_basic_2.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.connect!
|
5
|
+
|
6
|
+
class Book
|
7
|
+
include Mongous::Document
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
p count = Book.filter.count
|
12
|
+
puts
|
13
|
+
|
14
|
+
p count = Book.filter[0..4].count
|
15
|
+
puts
|
16
|
+
|
17
|
+
p count = Book.filter[0...4].count
|
18
|
+
puts
|
19
|
+
|
20
|
+
p count = Book.filter[0, 4].count
|
21
|
+
puts
|
22
|
+
|
23
|
+
p count = Book.filter[20,10].count
|
24
|
+
puts
|
25
|
+
|
26
|
+
pp books = Book.filter[0, 2].all
|
27
|
+
puts
|
28
|
+
|
29
|
+
filter = Book.filter( title: /title/ )
|
30
|
+
filter[0, 4].each do |book|
|
31
|
+
p book
|
32
|
+
end
|
33
|
+
puts
|
34
|
+
filter[4, 4].each do |book|
|
35
|
+
p book
|
36
|
+
end
|
37
|
+
puts
|
38
|
+
|
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.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arimay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongo
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- sample/query_basic_4.rb
|
99
99
|
- sample/query_basic_5.rb
|
100
100
|
- sample/query_basic_6.rb
|
101
|
+
- sample/query_basic_7.rb
|
101
102
|
- sample/query_detail_1.rb
|
102
103
|
- sample/query_detail_2.rb
|
103
104
|
- sample/query_detail_3.rb
|