Module: Sequel::ActiveRecordConnection::Postgres::ConnectionMethods
- Defined in:
- lib/sequel/extensions/activerecord_connection/postgres.rb
Overview
Copy-pasted from Sequel::Postgres::Adapter.
Constant Summary collapse
- DISCONNECT_ERROR_CLASSES =
The underlying exception classes to reraise as disconnect errors instead of regular database errors.
[IOError, Errno::EPIPE, Errno::ECONNRESET, ::PG::ConnectionBad].freeze
- DISCONNECT_ERROR_REGEX =
Since exception class based disconnect checking may not work, also trying parsing the exception message to look for disconnect errors.
/\A#{Regexp.union([ "ERROR: cached plan must not change result type", "could not receive data from server", "no connection to the server", "connection not open", "connection is closed", "terminating connection due to administrator command", "PQconsumeInput() " ])}/
Instance Method Summary collapse
- #async_exec_params(sql, args) ⇒ Object
-
#check_disconnect_errors ⇒ Object
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.
-
#execute(sql, args = nil) ⇒ Object
Execute the given SQL with this connection.
Instance Method Details
#async_exec_params(sql, args) ⇒ Object
48 49 50 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 48 def async_exec_params(sql, args) defined?(super) ? super : async_exec(sql, args) end |
#check_disconnect_errors ⇒ Object
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.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 55 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. =~ 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) ⇒ Object
Execute the given SQL with this connection. If a block is given, yield the results, otherwise, return the number of changed rows.
79 80 81 82 83 84 85 86 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 79 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 |