module Sequel::Postgres::HStore::DatabaseMethods

Public Class Methods

extended(db) click to toggle source
# File lib/sequel/extensions/pg_hstore.rb, line 142
def self.extended(db)
  db.instance_eval do
    add_named_conversion_procs(conversion_procs, :hstore=>PG_NAMED_TYPES[:hstore])
    @schema_type_classes[:hstore] = HStore
  end
end

Public Instance Methods

bound_variable_arg(arg, conn) click to toggle source

Handle hstores in bound variables

Calls superclass method
# File lib/sequel/extensions/pg_hstore.rb, line 150
def bound_variable_arg(arg, conn)
  case arg
  when HStore
    arg.unquoted_literal
  when Hash
    HStore.new(arg).unquoted_literal
  else
    super
  end
end

Private Instance Methods

schema_column_type(db_type) click to toggle source

Recognize the hstore database type.

Calls superclass method
# File lib/sequel/extensions/pg_hstore.rb, line 164
def schema_column_type(db_type)
  db_type == 'hstore' ? :hstore : super
end
typecast_value_hstore(value) click to toggle source

Typecast value correctly to HStore. If already an HStore instance, return as is. If a hash, return an HStore version of it. If a string, assume it is in PostgreSQL output format and parse it using the parser.

# File lib/sequel/extensions/pg_hstore.rb, line 173
def typecast_value_hstore(value)
  case value
  when HStore
    value
  when Hash
    HStore.new(value)
  else
    raise Sequel::InvalidValue, "invalid value for hstore: #{value.inspect}"
  end
end