Sha256: ef1ce44a6e963fab3430d6d49adc4b62f44cf06217b52bab9b8238b75e493d26

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

# frozen_string_literal: true

module ActiveRecord
  module Store
    class FlexibleJsonb < ActiveRecord::Store::FlexibleStore
      def delete_keys(*keys)
        keys.flatten!
        query = String.new "#{store_name} = #{store_name}"
        keys.length.times { query.concat(' - ?') }
        relation.update_all([query, *keys])
      end

      def merge(pairs)
        relation.update_all(["#{store_name} = #{store_name} || ?::jsonb", pairs.to_json])
      end

      def delete_pairs(pairs)
        keys = pairs.keys
        pairs = pairs.map { |k,v| { k => v } }
        @relation = relation.where.store(store_name, *pairs)
        delete_keys(keys)
      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_jsonb.rb
pgrel-0.2.0 lib/pgrel/active_record/store/flexible_jsonb.rb