Class: Athens::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/athens/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(database: nil, aws_client_override: {}) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/athens/connection.rb', line 8

def initialize(database: nil, aws_client_override: {})
  @database_name = database

  client_config = {
    access_key_id: Athens.configuration.aws_access_key,
    secret_access_key: Athens.configuration.aws_secret_key,
    region: Athens.configuration.aws_region,
    profile: Athens.configuration.aws_profile
  }.merge(aws_client_override).compact

  @client = Aws::Athena::Client.new(client_config)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/athens/connection.rb', line 6

def client
  @client
end

#database_nameObject (readonly)

Returns the value of attribute database_name.



5
6
7
# File 'lib/athens/connection.rb', line 5

def database_name
  @database_name
end

Instance Method Details

#execute(query, request_token: nil, work_group: nil) ⇒ Object

Runs a query against Athena, returning an Athens::Query object that you can use to wait for it to finish or get the results



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/athens/connection.rb', line 23

def execute(query, request_token: nil, work_group: nil)
  if @database_name
    resp = @client.start_query_execution(
      query_string: query,
      query_execution_context: context,
      result_configuration: result_config,
      client_request_token: request_token,
      work_group: work_group
    )
  else
    resp = @client.start_query_execution(
      query_string: query,
      result_configuration: result_config
    )
  end

  return Athens::Query.new(self, resp.query_execution_id)
end