dm-redis-adapter 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dm-redis-adapter/adapter.rb +24 -5
- data/spec/dm_redis_finding_spec.rb +80 -0
- metadata +6 -4
@@ -183,10 +183,14 @@ module DataMapper
|
|
183
183
|
value = operand.first.value
|
184
184
|
elsif operand.subject.is_a?(DataMapper::Associations::ManyToOne::Relationship)
|
185
185
|
subject = operand.subject.child_key.first
|
186
|
-
value = operand.
|
186
|
+
value = if operand.is_a?(DataMapper::Query::Conditions::InclusionComparison)
|
187
|
+
operand.value.map{|v|v[operand.subject.parent_key.first.name]}
|
188
|
+
else
|
189
|
+
operand.value[operand.subject.parent_key.first.name]
|
190
|
+
end
|
187
191
|
else
|
188
192
|
subject = operand.subject
|
189
|
-
value =
|
193
|
+
value = operand.value
|
190
194
|
end
|
191
195
|
|
192
196
|
if subject.is_a?(DataMapper::Associations::ManyToOne::Relationship)
|
@@ -200,12 +204,27 @@ module DataMapper
|
|
200
204
|
matched_records << {redis_key_for(query.model) => key}
|
201
205
|
end
|
202
206
|
end
|
207
|
+
elsif operand.is_a?(DataMapper::Query::Conditions::InclusionComparison)
|
208
|
+
value.each do |val|
|
209
|
+
if @redis.sismember(key_set_for(query.model), val)
|
210
|
+
matched_records << {redis_key_for(query.model) => val}
|
211
|
+
end
|
212
|
+
end
|
203
213
|
elsif @redis.sismember(key_set_for(query.model), value)
|
204
214
|
matched_records << {redis_key_for(query.model) => value}
|
205
215
|
end
|
206
|
-
elsif subject.index
|
207
|
-
|
208
|
-
|
216
|
+
elsif subject.respond_to?( :index ) && subject.index
|
217
|
+
if operand.is_a?(DataMapper::Query::Conditions::NotOperation)
|
218
|
+
elsif operand.is_a?(DataMapper::Query::Conditions::InclusionComparison)
|
219
|
+
value.each do |val|
|
220
|
+
find_indexed_matches(subject, val).each do |k|
|
221
|
+
matched_records << {redis_key_for(query.model) => k.to_i, "#{subject.name}" => val}
|
222
|
+
end
|
223
|
+
end
|
224
|
+
else
|
225
|
+
find_indexed_matches(subject, value).each do |k|
|
226
|
+
matched_records << {redis_key_for(query.model) => k.to_i, "#{subject.name}" => value}
|
227
|
+
end
|
209
228
|
end
|
210
229
|
else # worst case, loop through each record and match
|
211
230
|
@redis.smembers(key_set_for(query.model)).each do |key|
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataMapper::Adapters::RedisAdapter do
|
4
|
+
before(:all) do
|
5
|
+
@adapter = DataMapper.setup(:default, {
|
6
|
+
:adapter => "redis",
|
7
|
+
:db => 15
|
8
|
+
})
|
9
|
+
@redis = Redis.new(:db => 15)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "finding records tests" do
|
13
|
+
before(:all) do
|
14
|
+
@redis.flushdb
|
15
|
+
class Page
|
16
|
+
include DataMapper::Resource
|
17
|
+
|
18
|
+
property :id, Serial
|
19
|
+
|
20
|
+
has n, :children, 'Page', :child_key => :parent_id
|
21
|
+
belongs_to :parent, 'Page', :required => false
|
22
|
+
end
|
23
|
+
DataMapper.finalize
|
24
|
+
|
25
|
+
@a = Page.create
|
26
|
+
@b = Page.create :parent => @a
|
27
|
+
@c = Page.create :parent => @a
|
28
|
+
@d = Page.create :parent => @c
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should find Page.all :parent_id => @a.id' do
|
32
|
+
found = Page.all :parent_id => @a.id
|
33
|
+
found.should == [@b,@c]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should find Page.all :id.not => @a.id' do
|
37
|
+
found = Page.all :id.not => @a.id
|
38
|
+
found.should == [@b,@c,@d]
|
39
|
+
end
|
40
|
+
|
41
|
+
# it fails
|
42
|
+
#it 'should find Page.all :parent_id.not => @a.id' do
|
43
|
+
# found = Page.all :parent_id.not => @a.id
|
44
|
+
# found.should == [@a,@d]
|
45
|
+
#end
|
46
|
+
|
47
|
+
it 'should find Page.all :parent => @a' do
|
48
|
+
found = Page.all :parent => @a
|
49
|
+
found.should == [@b,@c]
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should find Page.all :id => [@a.id]' do
|
53
|
+
found = Page.all :id => [@a.id]
|
54
|
+
found.should == [@a]
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should find Page.all :id => [@a.id, @c.id]' do
|
58
|
+
found = Page.all :id => [@a.id, @c.id]
|
59
|
+
found.should == [@a,@c]
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should find Page.all :parent_id => [@a.id, @c.id]' do
|
63
|
+
found = Page.all :parent_id => [@a.id, @c.id]
|
64
|
+
found.should == [@b,@c,@d]
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should find Page.all :parent => [@a,@c]' do
|
68
|
+
found = Page.all :parent => [@a,@c]
|
69
|
+
found.should == [@b,@c,@d]
|
70
|
+
end
|
71
|
+
|
72
|
+
# it fails
|
73
|
+
#it 'should be able to map Page.all.map{ |@a| @a.parent }' do
|
74
|
+
# mapped = Page.all.map{ |a| a.parent }
|
75
|
+
# mapped.should == [nil, @a, @a, @c]
|
76
|
+
#end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dan Herrera
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-11-
|
17
|
+
date: 2011-11-14 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/dm-redis-adapter/adapter.rb
|
93
93
|
- lib/dm-redis-adapter/spec/setup.rb
|
94
94
|
- spec/dm_redis_associations_spec.rb
|
95
|
+
- spec/dm_redis_finding_spec.rb
|
95
96
|
- spec/dm_redis_spec.rb
|
96
97
|
- spec/dm_redis_validations_spec.rb
|
97
98
|
- spec/spec_helper.rb
|
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
110
|
requirements:
|
110
111
|
- - ">="
|
111
112
|
- !ruby/object:Gem::Version
|
112
|
-
hash:
|
113
|
+
hash: 82707661945259695
|
113
114
|
segments:
|
114
115
|
- 0
|
115
116
|
version: "0"
|
@@ -130,6 +131,7 @@ specification_version: 3
|
|
130
131
|
summary: DataMapper adapter for the Redis key-value database
|
131
132
|
test_files:
|
132
133
|
- spec/dm_redis_associations_spec.rb
|
134
|
+
- spec/dm_redis_finding_spec.rb
|
133
135
|
- spec/dm_redis_spec.rb
|
134
136
|
- spec/dm_redis_validations_spec.rb
|
135
137
|
- spec/spec_helper.rb
|