module Sequel::Postgres::HStore::DatabaseMethods

Public Class Methods

extended(db) click to toggle source
    # File lib/sequel/extensions/pg_hstore.rb
131 def self.extended(db)
132   db.instance_exec do
133     add_named_conversion_proc(:hstore, &HStore.method(:parse))
134     @schema_type_classes[:hstore] = HStore
135   end
136 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
139 def bound_variable_arg(arg, conn)
140   case arg
141   when HStore
142     arg.unquoted_literal
143   when Hash
144     HStore.new(arg).unquoted_literal
145   else
146     super
147   end
148 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
153 def schema_column_type(db_type)
154   db_type == 'hstore' ? :hstore : super
155 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
158 def schema_post_process(_)
159   super.each do |a|
160     h = a[1]
161     if h[:type] == :hstore && h[:default] =~ /\A''::hstore\z/
162       h[:callable_default] = lambda{HStore.new({})}
163     end
164   end
165 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
172 def typecast_value_hstore(value)
173   case value
174   when HStore
175     value
176   when Hash
177     HStore.new(value)
178   else
179     raise Sequel::InvalidValue, "invalid value for hstore: #{value.inspect}"
180   end
181 end