module Sequel::ActiveRecordConnection::Postgres::ConnectionMethods

Copy-pasted from Sequel::Postgres::Adapter.

Constants

DISCONNECT_ERROR_CLASSES

The underlying exception classes to reraise as disconnect errors instead of regular database errors.

DISCONNECT_ERROR_REGEX

Since exception class based disconnect checking may not work, also trying parsing the exception message to look for disconnect errors.

Public Instance Methods

async_exec_params(sql, args) click to toggle source
Calls superclass method
# File lib/sequel/extensions/activerecord_connection/postgres.rb, line 40
def async_exec_params(sql, args)
  defined?(super) ? super : async_exec(sql, args)
end
check_disconnect_errors() { || ... } click to toggle source

Raise a Sequel::DatabaseDisconnectError if a one of the disconnect error classes is raised, or a PG::Error is raised and the connection status cannot be determined or it is not OK.

# File lib/sequel/extensions/activerecord_connection/postgres.rb, line 47
def check_disconnect_errors
  begin
    yield
  rescue *DISCONNECT_ERROR_CLASSES => e
    disconnect = true
    raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError))
  rescue PG::Error => e
    disconnect = false
    begin
      s = status
    rescue PG::Error
      disconnect = true
    end
    status_ok = (s == PG::CONNECTION_OK)
    disconnect ||= !status_ok
    disconnect ||= e.message =~ DISCONNECT_ERROR_REGEX
    disconnect ? raise(Sequel.convert_exception_class(e, Sequel::DatabaseDisconnectError)) : raise
  ensure
    block if status_ok && !disconnect
  end
end
execute(sql, args = nil) { |result| ... } click to toggle source

Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.

# File lib/sequel/extensions/activerecord_connection/postgres.rb, line 71
def execute(sql, args = nil)
  args   = args.map { |v| @db.bound_variable_arg(v, self) } if args
  result = check_disconnect_errors { execute_query(sql, args) }

  block_given? ? yield(result) : result.cmd_tuples
ensure
  result.clear if result
end

Private Instance Methods

execute_query(sql, args) click to toggle source

Return the PG::Result containing the query results.

# File lib/sequel/extensions/activerecord_connection/postgres.rb, line 83
def execute_query(sql, args)
  @db.log_connection_yield(sql, self, args) do
    Utils.set_value(self, :type_map_for_results, PG::TypeMapAllStrings.new) do
      args ? async_exec_params(sql, args) : async_exec(sql)
    end
  end
end