Module: Hypostasis::ColumnGroup::Findable::ClassMethods

Defined in:
lib/hypostasis/column_group/findable.rb

Instance Method Summary collapse

Instance Method Details

#find(id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/hypostasis/column_group/findable.rb', line 6

def find(id)
  document_keys = namespace.transact do |tr|
    tr.get_range_start_with(namespace.for_column_group(self, id), {:streaming_mode => :want_all}).to_a
  end
  raise Hypostasis::Errors::ColumnGroupNotFound if document_keys.empty?
  reconstitute_column_group(document_keys)
end

#find_where(field_value_pairs) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hypostasis/column_group/findable.rb', line 14

def find_where(field_value_pairs)
  results = []
  namespace.transact do |tr|
    field_value_pairs.each do |field, value|
      results << tr.get_range_start_with(namespace.for_index(self, field, value), {:streaming_mode => :want_all}).to_a
    end
  end
  results.flatten!
  results.collect! {|result| Hypostasis::Tuple.unpack(result.key.split('\\').last).to_a.last }.compact!
  results.select! {|e| results.count(e) == field_value_pairs.size}
  results.uniq!
  results.collect! {|result| find(result) }
end