Class: ActiveRecordDataLoader::ConnectionHandler
- Inherits:
-
Object
- Object
- ActiveRecordDataLoader::ConnectionHandler
- Defined in:
- lib/active_record_data_loader/connection_handler.rb
Instance Method Summary collapse
-
#initialize(connection_factory:, statement_timeout:) ⇒ ConnectionHandler
constructor
A new instance of ConnectionHandler.
- #reset_timeout_command ⇒ Object
- #supports_copy? ⇒ Boolean
- #supports_timeout? ⇒ Boolean
- #timeout_set_command ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(connection_factory:, statement_timeout:) ⇒ ConnectionHandler
Returns a new instance of ConnectionHandler.
5 6 7 8 9 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 5 def initialize(connection_factory:, statement_timeout:) @connection_factory = connection_factory @statement_timeout = statement_timeout cache_facts end |
Instance Method Details
#reset_timeout_command ⇒ Object
36 37 38 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 36 def reset_timeout_command "RESET statement_timeout" end |
#supports_copy? ⇒ Boolean
28 29 30 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 28 def supports_copy? @supports_copy end |
#supports_timeout? ⇒ Boolean
24 25 26 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 24 def supports_timeout? @supports_timeout end |
#timeout_set_command ⇒ Object
32 33 34 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 32 def timeout_set_command "SET statement_timeout = \"#{statement_timeout}\"" end |
#with_connection ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record_data_loader/connection_handler.rb', line 11 def with_connection connection = connection_factory.call if supports_timeout? connection.execute(timeout_set_command) yield connection connection.execute(reset_timeout_command) else yield connection end ensure connection&.close end |