Class: Bricolage::MySQLDataSource
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
#database ⇒ Object
34
35
36
|
# File 'lib/bricolage/mysqldatasource.rb', line 34
def database
@mysql_options[:database]
end
|
#host ⇒ Object
18
19
20
|
# File 'lib/bricolage/mysqldatasource.rb', line 18
def host
@mysql_options[:host]
end
|
#new_task ⇒ Object
38
39
40
|
# File 'lib/bricolage/mysqldatasource.rb', line 38
def new_task
MySQLTask.new(self)
end
|
#open ⇒ Object
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
|
#password ⇒ Object
30
31
32
|
# File 'lib/bricolage/mysqldatasource.rb', line 30
def password
@mysql_options[:password]
end
|
#port ⇒ Object
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
|
#username ⇒ Object
26
27
28
|
# File 'lib/bricolage/mysqldatasource.rb', line 26
def username
@mysql_options[:username]
end
|