Class: ActiveRecord::ConnectionAdapters::NeverBlockPostgreSQLAdapter
- Inherits:
-
PostgreSQLAdapter
- Object
- PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::NeverBlockPostgreSQLAdapter
- Defined in:
- lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb
Instance Method Summary collapse
-
#adapter_name ⇒ Object
Returns ‘FiberedPostgreSQL’ as adapter name for identification purposes.
- #begin_db_transaction ⇒ Object
- #commit_db_transaction ⇒ Object
- #connect ⇒ Object
-
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
Executes an INSERT query and returns the new record’s ID, this wont work on earlier versions of PostgreSQL but they don’t suppor the async interface anyway.
-
#reconnect! ⇒ Object
Close then reopen the connection.
- #rollback_db_transaction ⇒ Object
Instance Method Details
#adapter_name ⇒ Object
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 |
#begin_db_transaction ⇒ Object
12 13 14 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 12 def begin_db_transaction @connection.begin_db_transaction end |
#commit_db_transaction ⇒ Object
16 17 18 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 16 def commit_db_transaction @connection.commit_db_transaction end |
#connect ⇒ Object
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 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 30 def connect @connection = ::NB::DB::PooledFiberedPostgresConnection.new(@connection_options[0]) do conn = PGconn.connect(*@connection_options[1..(@connection_options.length-1)]) PGconn.translate_results = false if PGconn.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 end end |
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
Executes an INSERT query and returns the new record’s ID, this wont work on earlier versions of PostgreSQL but they don’t suppor the async interface anyway
26 27 28 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 26 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) @connection.exec(sql << " returning id ") end |
#reconnect! ⇒ Object
Close then reopen the connection.
66 67 68 69 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 66 def reconnect! disconnect! connect end |
#rollback_db_transaction ⇒ Object
20 21 22 |
# File 'lib/active_record/connection_adapters/neverblock_postgresql_adapter.rb', line 20 def rollback_db_transaction @connection.rollback_db_transaction end |