Class: PgReports::Executor
- Inherits:
-
Object
- Object
- PgReports::Executor
- Defined in:
- lib/pg_reports/executor.rb
Overview
Executes SQL queries and returns results.
The connection is resolved lazily on every #execute call so that thread-local context set by PgReports.with_target / with_database is honored even when an Executor instance has been memoized at the module level.
Instance Method Summary collapse
-
#connection ⇒ Object
Resolved on every call: explicit override > thread-local > registry default.
-
#execute(sql, **params) ⇒ Object
Execute raw SQL and return results as array of hashes.
-
#execute_from_file(category, name, **params) ⇒ Object
Execute SQL from a file and return results as array of hashes.
-
#initialize(connection: nil) ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize(connection: nil) ⇒ Executor
Returns a new instance of Executor.
10 11 12 |
# File 'lib/pg_reports/executor.rb', line 10 def initialize(connection: nil) @connection_override = connection end |
Instance Method Details
#connection ⇒ Object
Resolved on every call: explicit override > thread-local > registry default.
28 29 30 |
# File 'lib/pg_reports/executor.rb', line 28 def connection @connection_override || PgReports.config.connection end |
#execute(sql, **params) ⇒ Object
Execute raw SQL and return results as array of hashes
21 22 23 24 25 |
# File 'lib/pg_reports/executor.rb', line 21 def execute(sql, **params) processed_sql = interpolate_params(sql, params) result = connection.exec_query(processed_sql) result.to_a end |