Class: Nquery::QueryRunner
- Inherits:
-
Object
- Object
- Nquery::QueryRunner
- Defined in:
- lib/nquery/query_runner.rb
Defined Under Namespace
Classes: Error, PermissionError
Constant Summary collapse
- FORBIDDEN_KEYWORDS =
/\b(INSERT|UPDATE|DELETE|DROP|ALTER|CREATE|TRUNCATE|GRANT|REVOKE|INTO)\b/i
Instance Method Summary collapse
-
#initialize(data_source:, statement:, user: nil, query: nil) ⇒ QueryRunner
constructor
A new instance of QueryRunner.
- #run ⇒ Object
Constructor Details
#initialize(data_source:, statement:, user: nil, query: nil) ⇒ QueryRunner
Returns a new instance of QueryRunner.
10 11 12 13 14 15 |
# File 'lib/nquery/query_runner.rb', line 10 def initialize(data_source:, statement:, user: nil, query: nil) @data_source = data_source @statement = statement.to_s.strip @user = user @query = query end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nquery/query_runner.rb', line 17 def run validate_statement! adapter = DataSources::Adapter.for(@data_source) result = adapter.execute_readonly( @statement, timeout: Nquery.configuration.query_timeout, row_limit: Nquery.configuration.query_row_limit ) record_audit!(result, "success") result rescue PermissionError raise rescue StandardError => e record_audit!({}, "error", e.) raise Error, e. end |