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.
Sequel::Postgres::Adapter::DISCONNECT_ERROR_CLASSES
- DISCONNECT_ERROR_REGEX =
Since exception class based disconnect checking may not work, also trying parsing the exception message to look for disconnect errors.
Sequel::Postgres::Adapter::DISCONNECT_ERROR_RE
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
59 60 61 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 59 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 66 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.
90 91 92 93 94 95 96 97 |
# File 'lib/sequel/extensions/activerecord_connection/postgres.rb', line 90 def execute(sql, args = nil) args = args.map { |v| @db.bound_variable_arg(v, self) } if args q = check_disconnect_errors { execute_query(sql, args) } block_given? ? yield(q) : q.cmd_tuples ensure q.clear if q && q.respond_to?(:clear) end |