class Upsert::MergeFunction::Postgresql::HstoreDeleteHandler

Attributes

column_definition[R]
merge_function[R]

Public Class Methods

new(merge_function, column_definition) click to toggle source
# File lib/upsert/merge_function/postgresql.rb, line 267
def initialize(merge_function, column_definition)
  @merge_function = merge_function
  @column_definition = column_definition
end

Public Instance Methods

name() click to toggle source
# File lib/upsert/merge_function/postgresql.rb, line 271
def name
  column_definition.name
end
to_arg() click to toggle source
# File lib/upsert/merge_function/postgresql.rb, line 274
def to_arg
  "#{quoted_name} text[]"
end
to_pgsql() click to toggle source
# File lib/upsert/merge_function/postgresql.rb, line 281
def to_pgsql
  %{
    IF array_length(#{quoted_name}, 1) > 0 THEN
      UPDATE #{merge_function.quoted_table_name} SET #{to_setter}
        WHERE #{merge_function.selector_column_definitions.map(&:to_selector).join(' AND ') };
    END IF;
  }.gsub(/\s+/, ' ')
end
to_setter() click to toggle source

use coalesce(foo, '{}':text[])

# File lib/upsert/merge_function/postgresql.rb, line 278
def to_setter
  "#{column_definition.quoted_name} = DELETE(#{column_definition.quoted_name}, #{quoted_name})"
end

Private Instance Methods

quoted_name() click to toggle source
# File lib/upsert/merge_function/postgresql.rb, line 290
def quoted_name
  @quoted_name ||= merge_function.connection.quote_ident "_delete_#{column_definition.name}"
end