Class: Infrataster::Contexts::PgsqlQueryContext

Inherits:
BaseContext
  • Object
show all
Defined in:
lib/infrataster/contexts/pgsql_query_context.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/infrataster/contexts/pgsql_query_context.rb', line 24

def connection
  options = {port: 5432, user: 'postgres', password: '', dbname: ''}
  if server.options[:pgsql]
    options = options.merge(server.options[:pgsql])
  end

  server.forward_port(options[:port]) do |address, new_port|
    connect = PG::Connection.new(
      :host => address,
      :port => new_port,
      :user => options[:user],
      :password => options[:password],
      :dbname => options[:dbname]
    )
  end
end

#resultObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/infrataster/contexts/pgsql_query_context.rb', line 7

def result
  options = {port: 5432, user: 'postgres', password: '', dbname: ''}
  if server.options[:pgsql]
    options = options.merge(server.options[:pgsql])
  end

  server.forward_port(options[:port]) do |address, new_port|
    connect = PG::Connection.new(
      :host => address,
      :port => new_port,
      :user => options[:user],
      :password => options[:password],
      :dbname => options[:dbname]
    )
	  connect.exec(resource.query) 
  end
end