module Sequel::Postgres::HStore::DatabaseMethods

Public Class Methods

extended(db) click to toggle source
    # File lib/sequel/extensions/pg_hstore.rb
137 def self.extended(db)
138   db.instance_exec do
139     add_named_conversion_proc(:hstore, &HStore.method(:parse))
140     @schema_type_classes[:hstore] = HStore
141   end
142 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
145 def bound_variable_arg(arg, conn)
146   case arg
147   when HStore
148     arg.unquoted_literal
149   when Hash
150     HStore.new(arg).unquoted_literal
151   else
152     super
153   end
154 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
159 def schema_column_type(db_type)
160   db_type == 'hstore' ? :hstore : super
161 end
schema_post_process(_) click to toggle source

Set the :callable_default value if the default value is recognized as an empty hstore.

Calls superclass method
    # File lib/sequel/extensions/pg_hstore.rb
164 def schema_post_process(_)
165   super.each do |a|
166     h = a[1]
167     if h[:type] == :hstore && h[:default] =~ /\A''::hstore\z/
168       h[:callable_default] = lambda{HStore.new({})}
169     end
170   end
171 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
178 def typecast_value_hstore(value)
179   case value
180   when HStore
181     value
182   when Hash
183     HStore.new(value)
184   else
185     raise Sequel::InvalidValue, "invalid value for hstore: #{value.inspect}"
186   end
187 end