# File lib/sequel/extensions/pg_hstore.rb, line 131 def self.extended(db) db.instance_exec do add_named_conversion_proc(:hstore, &HStore.method(:parse)) @schema_type_classes[:hstore] = HStore end end
Handle hstores in bound variables
# File lib/sequel/extensions/pg_hstore.rb, line 139 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 153 def schema_column_type(db_type) db_type == 'hstore' ? :hstore : super end
Set the :callable_default value if the default value is recognized as an empty hstore.
# File lib/sequel/extensions/pg_hstore.rb, line 158 def schema_post_process(_) super.each do |a| h = a[1] if h[:type] == :hstore && h[:default] =~ /\A''::hstore\z/ h[:callable_default] = lambda{HStore.new({})} end end 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 172 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