Class: Bricolage::MySQLDataSource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Attribute Details

#mysql_optionsObject (readonly)

Returns the value of attribute mysql_options.



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

def mysql_options
  @mysql_options
end

Instance Method Details

#databaseObject



36
37
38
# File 'lib/bricolage/mysqldatasource.rb', line 36

def database
  @mysql_options[:database]
end

#hostObject



20
21
22
# File 'lib/bricolage/mysqldatasource.rb', line 20

def host
  @mysql_options[:host]
end

#new_taskObject



40
41
42
# File 'lib/bricolage/mysqldatasource.rb', line 40

def new_task
  MySQLTask.new(self)
end

#openObject



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

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

#passwordObject



32
33
34
# File 'lib/bricolage/mysqldatasource.rb', line 32

def password
  @mysql_options[:password]
end

#portObject



24
25
26
# File 'lib/bricolage/mysqldatasource.rb', line 24

def port
  @mysql_options[:port]
end

#query(sql, **opts) ⇒ Object



55
56
57
58
59
# File 'lib/bricolage/mysqldatasource.rb', line 55

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

#usernameObject



28
29
30
# File 'lib/bricolage/mysqldatasource.rb', line 28

def username
  @mysql_options[:username]
end