Class: Flydata::Parser::Mysql::FdMysqlClient
- Inherits:
-
Mysql2::Client
- Object
- Mysql2::Client
- Flydata::Parser::Mysql::FdMysqlClient
- Defined in:
- lib/flydata/parser/mysql/dump_parser.rb
Overview
Custom mysql client that sets config params (eg:-read_timeout) uniformly for all mysql access. Also, gives access to the last query that was executed using the client which can be helpful when handling exceptions
Instance Attribute Summary collapse
-
#last_query ⇒ Object
Returns the value of attribute last_query.
Instance Method Summary collapse
-
#initialize(db_opts) ⇒ FdMysqlClient
constructor
A new instance of FdMysqlClient.
- #query(sql, options = {}) ⇒ Object
Constructor Details
#initialize(db_opts) ⇒ FdMysqlClient
Returns a new instance of FdMysqlClient.
218 219 220 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 218 def initialize(db_opts) super(db_opts.merge(read_timeout: 600)) end |
Instance Attribute Details
#last_query ⇒ Object
Returns the value of attribute last_query.
216 217 218 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 216 def last_query @last_query end |
Instance Method Details
#query(sql, options = {}) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/flydata/parser/mysql/dump_parser.rb', line 222 def query(sql, = {}) @last_query = sql begin super(sql, ) rescue Mysql2::Error => e if /^Timeout waiting for a response/ === e.to_s raise "The below query timed out when running. Please check long running processes and locks in your database.\n#{last_query}" end raise e end end |