Class: Mysql2::Client
- Inherits:
-
Object
- Object
- Mysql2::Client
- Defined in:
- lib/mysql2/reconnect_with_readonly.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #query(sql, options = {}) ⇒ Object
-
#reconnect ⇒ Object
Mysql2::Client does not have a #reconnect method Mysql2::Client#close and Mysql2::Client#connect(*args) resulted in SEGV.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
72 73 74 75 |
# File 'lib/mysql2/reconnect_with_readonly.rb', line 72 def initialize(opts = {}) @opts = opts @original_client = Mysql2::ReconnectWithReadonly::OriginalClient.new(@opts) end |
Instance Method Details
#query(sql, options = {}) ⇒ Object
86 87 88 89 90 |
# File 'lib/mysql2/reconnect_with_readonly.rb', line 86 def query(sql, = {}) ReconnectWithReadonly.reconnect_with_readonly(self) do @original_client.query(sql, ) end end |
#reconnect ⇒ Object
Mysql2::Client does not have a #reconnect method Mysql2::Client#close and Mysql2::Client#connect(*args) resulted in SEGV. It is required to create a new Mysql2::Client instance for reconnection. This is why we wrap orginal client with this monkey pathced client.
81 82 83 84 |
# File 'lib/mysql2/reconnect_with_readonly.rb', line 81 def reconnect @original_client.close rescue nil @original_client = Mysql2::ReconnectWithReadonly::OriginalClient.new(@opts) end |