Class: Infrataster::Contexts::MysqlQueryContext

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

Instance Method Summary collapse

Instance Method Details

#resultsObject



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

def results
  options = {port: 3306, user: 'root', password: ''}
  if server.options[:mysql]
    options = options.merge(server.options[:mysql])
  end

  server.forward_port(options[:port]) do |address, new_port|
    client = Mysql2::Client.new(
      host: address,
      port: new_port,
      username: options[:user],
      password: options[:password],
    )
    client.query(resource.query)
  end
end