Sha256: ea42aceaafd9698122a137ba52eca0618756cd11d896132ec320835aa0b230f5

Contents?: true

Size: 762 Bytes

Versions: 2

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Store
    class FlexibleHstore < ActiveRecord::Store::FlexibleStore
      def delete_keys(*keys)
        keys = keys.flatten.map(&:to_s)
        relation.update_all(["#{store_name} = delete(#{store_name}, ARRAY[:keys])", keys: keys])
      end

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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pgrel-0.3.0 lib/pgrel/active_record/store/flexible_hstore.rb
pgrel-0.2.0 lib/pgrel/active_record/store/flexible_hstore.rb