Class: Bricolage::MySQLDataSource
- Inherits:
-
DataSource
- Object
- DataSource
- Bricolage::MySQLDataSource
- Defined in:
- lib/bricolage/mysqldatasource.rb
Instance Attribute Summary collapse
-
#mysql_options ⇒ Object
readonly
Returns the value of attribute mysql_options.
Instance Method Summary collapse
- #database ⇒ Object
- #host ⇒ Object
-
#initialize(**mysql_options) ⇒ MySQLDataSource
constructor
A new instance of MySQLDataSource.
- #new_task ⇒ Object
- #open ⇒ Object
- #password ⇒ Object
- #port ⇒ Object
- #query(sql, **opts) ⇒ Object
- #username ⇒ Object
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 = @client = nil end |
Instance Attribute Details
#mysql_options ⇒ Object (readonly)
Returns the value of attribute mysql_options.
18 19 20 |
# File 'lib/bricolage/mysqldatasource.rb', line 18 def @mysql_options end |
Instance Method Details
#database ⇒ Object
36 37 38 |
# File 'lib/bricolage/mysqldatasource.rb', line 36 def database @mysql_options[:database] end |
#host ⇒ Object
20 21 22 |
# File 'lib/bricolage/mysqldatasource.rb', line 20 def host @mysql_options[:host] end |
#new_task ⇒ Object
40 41 42 |
# File 'lib/bricolage/mysqldatasource.rb', line 40 def new_task MySQLTask.new(self) end |
#open ⇒ Object
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 |
#password ⇒ Object
32 33 34 |
# File 'lib/bricolage/mysqldatasource.rb', line 32 def password @mysql_options[:password] end |
#port ⇒ Object
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 |
#username ⇒ Object
28 29 30 |
# File 'lib/bricolage/mysqldatasource.rb', line 28 def username @mysql_options[:username] end |