Class: ActiveRecord::Store::FlexibleHstore

Inherits:
FlexibleStore show all
Defined in:
lib/pgrel/active_record/store/flexible_hstore.rb

Instance Attribute Summary

Attributes inherited from FlexibleStore

#relation, #store_name

Instance Method Summary collapse

Methods inherited from FlexibleStore

#initialize

Constructor Details

This class inherits a constructor from ActiveRecord::Store::FlexibleStore

Instance Method Details

#delete_keys(*keys) ⇒ Object



6
7
8
9
# File 'lib/pgrel/active_record/store/flexible_hstore.rb', line 6

def delete_keys(*keys)
  keys = keys.flatten.map(&:to_s)
  relation.update_all(["#{store_name} = delete(#{store_name}, ARRAY[:keys])", keys: keys])
end

#delete_pairs(pairs) ⇒ Object



16
17
18
19
20
21
# File 'lib/pgrel/active_record/store/flexible_hstore.rb', line 16

def delete_pairs(pairs)
  relation.update_all(
    ["#{store_name} = delete(#{store_name}, hstore(ARRAY[:keys], ARRAY[:values]))",
      keys: pairs.keys.map(&:to_s), values: pairs.values.map(&:to_s)]
  )
end

#merge(pairs) ⇒ Object



11
12
13
14
# File 'lib/pgrel/active_record/store/flexible_hstore.rb', line 11

def merge(pairs)
  relation.update_all(["#{store_name} = hstore(#{store_name}) || hstore(ARRAY[:keys])",
    keys: pairs.to_a.flatten.map(&:to_s)])
end