Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test case for composed natural keys

first attampts to get composed natural keyz working
  • Loading branch information...
commit aabc81fc9f0b69d04063f10761354c06c19c4135 1 parent 7173fa9
Sebastian Feuerstack authored Dan Herrera committed
Showing with 25 additions and 3 deletions.
  1. +24 −3 lib/dm-redis-adapter/adapter.rb
  2. +1 −0  spec/textual_keys_spec.rb
View
27 lib/dm-redis-adapter/adapter.rb
@@ -140,6 +140,27 @@ def update_attributes(resources)
end
end
+ def is_composed_key_based_query?(query)
+ fields_length = query.model.key.size
+ is_key = query.condition_properties.select { |field| field.key? }
+ (fields_length >1 and fields_length == is_key.length)
+ end
+
+ def key_query(query)
+ matched_records = []
+ value =""
+ storage_name = query.model.storage_name
+ query.conditions.operands.each do |operand|
+ value += operand.value
+ end
+
+ if @redis.sismember(key_set_for(query.model), value)
+ #matched_records << @redis.hgetall("#{storage_name}:#{value}")
+ matched_records << {redis_key_for(query.model) => value}
+ end
+ matched_records
+ end
+
##
# Retrieves records for a particular model.
#
@@ -158,6 +179,8 @@ def records_for(query)
key = key.to_i if key =~ /^\d+$/
keys << {redis_key_for(query.model) => key}
end
+ elsif is_composed_key_based_query?(query)
+ keys = key_query(query)
else
query.conditions.operands.each do |operand|
if operand.is_a?(DataMapper::Query::Conditions::OrOperation)
@@ -245,12 +268,10 @@ def perform_query(query, operand)
find_indexed_matches(subject, value).each do |k|
matched_records << {redis_key_for(query.model) => k, "#{subject.name}" => value}
end
- else # worst case here, loop through all members, typecast and match
- search_all_resources(query, operand, subject, matched_records)
end
else # worst case here, loop through all members, typecast and match
search_all_resources(query, operand, subject, matched_records)
- end
+ end
matched_records
end
View
1  spec/textual_keys_spec.rb
@@ -38,6 +38,7 @@ class Foo
Foo.create(:key1 => "value1", :key2 => 'value2')
Foo.first(:key1 => "value1").key2.should == 'value2'
+ # Foo.get("value1","value2").key2.should == 'value2'
end
end

0 comments on commit aabc81f

Please sign in to comment.
Something went wrong with that request. Please try again.