# File lib/sequel/extensions/pg_hstore.rb, line 144 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
Handle hstores in bound variables
# File lib/sequel/extensions/pg_hstore.rb, line 152 def bound_variable_arg(arg, conn) case arg when HStore arg.unquoted_literal when Hash HStore.new(arg).unquoted_literal else super end end
Recognize the hstore database type.
# File lib/sequel/extensions/pg_hstore.rb, line 166 def schema_column_type(db_type) db_type == 'hstore' ? :hstore : super end
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 175 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