Class: ActivePostgres::DirectExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/active_postgres/direct_executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (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

Returns:

  • (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

Returns:

  • (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.message}"
end