Class: Bricolage::MySQLDataSource

Inherits:
DataSource show all
Defined in:
lib/bricolage/mysqldatasource.rb

Constant Summary

Constants inherited from DataSource

DataSource::CLASSES

Instance Attribute Summary

Attributes inherited from DataSource

#context, #logger, #name

Instance Method Summary collapse

Methods inherited from DataSource

get_class, new_for_type, #open_for_batch, #redshift_loader_source?

Constructor Details

#initialize(**mysql_options) ⇒ MySQLDataSource

Returns a new instance of MySQLDataSource.



13
14
15
16
# File 'lib/bricolage/mysqldatasource.rb', line 13

def initialize(**mysql_options)
  @mysql_options = mysql_options
  @client = nil
end

Instance Method Details

#databaseObject



34
35
36
# File 'lib/bricolage/mysqldatasource.rb', line 34

def database
  @mysql_options[:database]
end

#hostObject



18
19
20
# File 'lib/bricolage/mysqldatasource.rb', line 18

def host
  @mysql_options[:host]
end

#new_taskObject



38
39
40
# File 'lib/bricolage/mysqldatasource.rb', line 38

def new_task
  MySQLTask.new(self)
end

#openObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/bricolage/mysqldatasource.rb', line 42

def open
  @client = Mysql2::Client.new(**@mysql_options)
  begin
    yield self
  ensure
    c = @client
    @client = nil
    c.close
  end
end

#passwordObject



30
31
32
# File 'lib/bricolage/mysqldatasource.rb', line 30

def password
  @mysql_options[:password]
end

#portObject



22
23
24
# File 'lib/bricolage/mysqldatasource.rb', line 22

def port
  @mysql_options[:port]
end

#query(sql, **opts) ⇒ Object



53
54
55
56
57
# File 'lib/bricolage/mysqldatasource.rb', line 53

def query(sql, **opts)
  logger.info "[SQL] #{sql}"
  connection_check
  @client.query(sql, **opts)
end

#usernameObject



26
27
28
# File 'lib/bricolage/mysqldatasource.rb', line 26

def username
  @mysql_options[:username]
end