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,
/closed MySQL connection/i,
/MySQL client is not connected/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
Instance Method Summary
collapse
Methods included from Adapter
#clear_semian_resource, #semian_resource
Class Method Details
.included(base) ⇒ Object
The naked methods are exposed as ‘raw_query` and `raw_connect` for instrumentation purpose
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/semian/mysql2.rb', line 45
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
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/semian/mysql2.rb', line 67
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
78
79
80
81
82
83
84
|
# File 'lib/semian/mysql2.rb', line 78
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
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/semian/mysql2.rb', line 56
def semian_identifier
@semian_identifier ||= begin
unless name = semian_options && semian_options[:name]
host = query_options[:host] || DEFAULT_HOST
port = query_options[:port] || DEFAULT_PORT
name = "#{host}:#{port}"
end
:"mysql_#{name}"
end
end
|