Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/freedom_patches/fast_pluck.rb

Overview

Note: In discourse, the following code is included in lib/sql_builder.rb

class RailsDateTimeDecoder < PG::SimpleDecoder

def decode(string, tuple=nil, field=nil)
  if Rails.version >= "4.2.0"
    @caster ||= ActiveRecord::Type::DateTime.new
    @caster.type_cast_from_database(string)
  else
    ActiveRecord::ConnectionAdapters::Column.string_to_time string
  end
end

end

class ActiveRecordTypeMap < PG::BasicTypeMapForResults

def initialize(connection)
  super(connection)
  rm_coder 0, 1114
  add_coder RailsDateTimeDecoder.new(name: "timestamp", oid: 1114, format: 0)
  # we don't need deprecations
  self.default_type_map = PG::TypeMapInRuby.new
end

end

def self.pg_type_map

conn = ActiveRecord::Base.connection.raw_connection
@typemap ||= ActiveRecordTypeMap.new(conn)

end

Instance Method Summary collapse

Instance Method Details

#select_raw(arel, name = nil, binds = [], &block) ⇒ Object



37
38
39
40
41
# File 'lib/freedom_patches/fast_pluck.rb', line 37

def select_raw(arel, name = nil, binds = [], &block)
  arel = arel_from_relation(arel)
  sql, binds = to_sql_and_binds(arel, binds)
  execute_and_clear(sql, name, binds, &block)
end