Class: PGconn

Inherits:
Object
  • Object
show all
Defined in:
lib/og/adapter/postgresql/override.rb,
lib/og/adapter/postgresql/override.rb

Overview

:nodoc: all

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PGconn

Returns a new instance of PGconn.


11
12
13
14
15
# File 'lib/og/adapter/postgresql/override.rb', line 11

def initialize(*args)
  initialize_pre_on_notice(*args)
  
  on_notice { |message| Logger.info message }
end

Class Method Details

.new(*args) ⇒ Object Also known as: connect


98
99
100
101
102
# File 'lib/og/adapter/postgresql/override.rb', line 98

def new(*args)
  new_pre_resque(*args)
rescue RuntimeError => e
  raise PGError, e.message
end

.new_pre_resqueObject


96
# File 'lib/og/adapter/postgresql/override.rb', line 96

alias_method :new_pre_resque, :new

Instance Method Details

#initialize_pre_on_noticeObject

Redirect notices from backend to the logger instead of stderr


10
# File 'lib/og/adapter/postgresql/override.rb', line 10

alias_method :initialize_pre_on_notice, :initialize

#on_notice(&block) ⇒ Object


107
108
109
# File 'lib/og/adapter/postgresql/override.rb', line 107

def on_notice(&block)
  @notice_processor = block
end

#query(*args) ⇒ Object Also known as: exec


86
87
88
89
90
91
# File 'lib/og/adapter/postgresql/override.rb', line 86

def query(*args)
  exec_old(*args)
# postgres-pr raises NoMethodError when querying if no conn is available
rescue RuntimeError, NoMethodError => e
  raise PGError, e.message
end

#query_pre_resqueObject


83
# File 'lib/og/adapter/postgresql/override.rb', line 83

alias_method :query_pre_resque, :query

#server_versionObject

call-seq:

conn.server_version -> Integer

The number is formed by converting the major, minor, and revision numbers into two-decimal-digit numbers and appending them together. For example, version 7.4.2 will be returned as 70402, and version 8.1 will be returned as 80100 (leading zeroes are not shown). Zero is returned if the connection is bad. See also parse_version.


31
32
33
34
35
# File 'lib/og/adapter/postgresql/override.rb', line 31

def server_version
  @server_version ||= parse_version(exec('SHOW server_version').first_value)
rescue PGError => e
  return 0
end