Class: ActiveRecord::ConnectionAdapters::NeverBlockPostgreSQLAdapter

Inherits:
PostgreSQLAdapter
  • Object
show all
Defined in:
lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#adapter_nameObject

Returns ‘FiberedPostgreSQL’ as adapter name for identification purposes.



8
9
10
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 8

def adapter_name
  'NeverBlockPostgreSQL'
end

#connectObject

def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)

  @connection.exec(sql << " returning id ") 
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 19

def connect
  @connection = ::NB::DB::PooledDBConnection.new(@connection_parameters[0]) do
    conn = ::NB::DB::FiberedPostgresConnection.connect(*@connection_parameters[1..(@connection_parameters.length-1)])
=begin
    ::NB::DB::FiberedPostgresConnection.translate_results = false if ::NB::DB::FiberedPostgresConnection.respond_to?(:translate_results=)
    # Ignore async_exec and async_query when using postgres-pr.
    @async = @config[:allow_concurrency] && @connection.respond_to?(:async_exec)
    # Use escape string syntax if available. We cannot do this lazily when encountering
    # the first string, because that could then break any transactions in progress.
    # See: http://www.postgresql.org/docs/current/static/runtime-config-compatible.html
    # If PostgreSQL doesn't know the standard_conforming_strings parameter then it doesn't
    # support escape string syntax. Don't override the inherited quoted_string_prefix.
    NB.neverblock(false) do
      if supports_standard_conforming_strings?
        self.class.instance_eval do
          define_method(:quoted_string_prefix) { 'E' }
        end
      end
      # Money type has a fixed precision of 10 in PostgreSQL 8.2 and below, and as of
      # PostgreSQL 8.3 it has a fixed precision of 19. PostgreSQLColumn.extract_precision
      # should know about this but can't detect it there, so deal with it here.
      money_precision = (postgresql_version >= 80300) ? 19 : 10
      ::ActiveRecord::ConnectionAdapters::PostgreSQLColumn.module_eval(<<-end_eval)
        def extract_precision(sql_type)
          if sql_type =~ /^money$/
            #{money_precision}
          else
            super
          end
        end
      end_eval
      #configure_connection
    end
	  conn
=end
  end
end

#reconnect!Object

Close then reopen the connection.



58
59
60
61
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 58

def reconnect!
  disconnect!
  connect
end