Class: ActivePostgres::DirectExecutor
- Inherits:
-
Object
- Object
- ActivePostgres::DirectExecutor
- Defined in:
- lib/active_postgres/direct_executor.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #get_postgres_status(host) ⇒ Object
-
#initialize(config, quiet: false) ⇒ DirectExecutor
constructor
A new instance of DirectExecutor.
- #postgres_running?(host) ⇒ Boolean
- #quiet? ⇒ Boolean
- #run_sql(host, sql) ⇒ Object
Constructor Details
#initialize(config, quiet: false) ⇒ DirectExecutor
Returns a new instance of DirectExecutor.
7 8 9 10 |
# File 'lib/active_postgres/direct_executor.rb', line 7 def initialize(config, quiet: false) @config = config @quiet = quiet end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/active_postgres/direct_executor.rb', line 5 def config @config end |
Instance Method Details
#get_postgres_status(host) ⇒ Object
34 35 36 |
# File 'lib/active_postgres/direct_executor.rb', line 34 def get_postgres_status(host) run_sql(host, 'SELECT version();') end |
#postgres_running?(host) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/active_postgres/direct_executor.rb', line 16 def postgres_running?(host) with_connection(host) do |conn| conn.exec('SELECT 1') true end rescue PG::Error false end |
#quiet? ⇒ Boolean
12 13 14 |
# File 'lib/active_postgres/direct_executor.rb', line 12 def quiet? @quiet end |
#run_sql(host, sql) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/active_postgres/direct_executor.rb', line 25 def run_sql(host, sql) with_connection(host) do |conn| result = conn.exec(sql) result.values.flatten.join("\n") end rescue PG::Error => e raise Error, "Failed to execute SQL on #{host}: #{e.}" end |