Module: Semian::Mysql2
- Includes:
- Adapter
- Defined in:
- lib/semian/mysql2.rb
Constant Summary collapse
- CONNECTION_ERROR =
Regexp.union( /Can't connect to MySQL server on/i, /Lost connection to MySQL server/i, /MySQL server has gone away/i, /Too many connections/i, )
- ResourceBusyError =
::Mysql2::ResourceBusyError
- CircuitOpenError =
::Mysql2::CircuitOpenError
- PingFailure =
Class.new(::Mysql2::Error)
- DEFAULT_HOST =
'localhost'
- DEFAULT_PORT =
3306
- QUERY_WHITELIST =
Regexp.union( /\A\s*ROLLBACK/i, /\A\s*COMMIT/i, /\A\s*RELEASE\s+SAVEPOINT/i, )
Class Method Summary collapse
-
.included(base) ⇒ Object
The naked methods are exposed as ‘raw_query` and `raw_connect` for instrumentation purpose.
Instance Method Summary collapse
Methods included from Adapter
Class Method Details
.included(base) ⇒ Object
The naked methods are exposed as ‘raw_query` and `raw_connect` for instrumentation purpose
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/semian/mysql2.rb', line 43 def self.included(base) base.send(:alias_method, :raw_query, :query) base.send(:remove_method, :query) base.send(:alias_method, :raw_connect, :connect) base.send(:remove_method, :connect) base.send(:alias_method, :raw_ping, :ping) base.send(:remove_method, :ping) end |
Instance Method Details
#ping ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/semian/mysql2.rb', line 65 def ping result = nil acquire_semian_resource(adapter: :mysql, scope: :ping) do result = raw_ping raise PingFailure.new(result.to_s) unless result end result rescue ResourceBusyError, CircuitOpenError, PingFailure false end |
#query(*args) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/semian/mysql2.rb', line 76 def query(*args) if query_whitelisted?(*args) raw_query(*args) else acquire_semian_resource(adapter: :mysql, scope: :query) { raw_query(*args) } end end |
#semian_identifier ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/semian/mysql2.rb', line 54 def semian_identifier @semian_identifier ||= begin unless name = && [:name] host = [:host] || DEFAULT_HOST port = [:port] || DEFAULT_PORT name = "#{host}:#{port}" end :"mysql_#{name}" end end |