Class: ActiveRecord::ConnectionAdapters::JanusMysql2Adapter
- Inherits:
-
Mysql2Adapter
- Object
- Mysql2Adapter
- ActiveRecord::ConnectionAdapters::JanusMysql2Adapter
- Defined in:
- lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb
Constant Summary collapse
- FOUND_ROWS =
'FOUND_ROWS'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_cache! ⇒ Object
- #connect! ⇒ Object
- #disconnect! ⇒ Object
- #execute(sql) ⇒ Object
- #execute_and_free(sql, name = nil, async: false) ⇒ Object
-
#initialize(*args) ⇒ JanusMysql2Adapter
constructor
A new instance of JanusMysql2Adapter.
- #raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true) ⇒ Object
- #reconnect! ⇒ Object
- #replica_connection ⇒ Object
- #with_connection(_args = {}) ⇒ Object
Constructor Details
#initialize(*args) ⇒ JanusMysql2Adapter
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 38 def initialize(*args) args[0][:janus]['replica']['database'] = args[0][:database] args[0][:janus]['primary']['database'] = args[0][:database] @replica_config = args[0][:janus]['replica'] args[0] = args[0][:janus]['primary'] super(*args) @connection_parameters ||= args[0] update_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
28 29 30 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 28 def config @config end |
Class Method Details
.dbconsole(config, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 31 def dbconsole(config, = {}) connection_config = Janus::DbConsoleConfig.new(config) super(connection_config, ) end |
Instance Method Details
#clear_cache! ⇒ Object
111 112 113 114 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 111 def clear_cache!(...) replica_connection.clear_cache!(...) super end |
#connect! ⇒ Object
96 97 98 99 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 96 def connect!(...) replica_connection.connect!(...) super end |
#disconnect! ⇒ Object
106 107 108 109 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 106 def disconnect!(...) replica_connection.disconnect!(...) super end |
#execute(sql) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 68 def execute(sql) case where_to_send?(sql) when :all send_to_replica(sql, connection: :all, method: :execute) super(sql) when :replica send_to_replica(sql, connection: :replica, method: :execute) else Janus::Context.stick_to_primary if write_query?(sql) Janus::Context.used_connection(:primary) super(sql) end end |
#execute_and_free(sql, name = nil, async: false) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 82 def execute_and_free(sql, name = nil, async: false) case where_to_send?(sql) when :all send_to_replica(sql, connection: :all, method: :execute) super(sql, name, async:) when :replica send_to_replica(sql, connection: :replica, method: :execute) else Janus::Context.stick_to_primary if write_query?(sql) Janus::Context.used_connection(:primary) super(sql, name, async:) end end |
#raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 54 def raw_execute(sql, name, async: false, allow_retry: false, materialize_transactions: true) case where_to_send?(sql) when :all send_to_replica(sql, connection: :all, method: :raw_execute) super when :replica send_to_replica(sql, connection: :replica, method: :raw_execute) else Janus::Context.stick_to_primary if write_query?(sql) Janus::Context.used_connection(:primary) super end end |
#reconnect! ⇒ Object
101 102 103 104 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 101 def reconnect!(...) replica_connection.reconnect!(...) super end |
#replica_connection ⇒ Object
116 117 118 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 116 def replica_connection @replica_connection ||= ActiveRecord::ConnectionAdapters::Mysql2Adapter.new(@replica_config) end |
#with_connection(_args = {}) ⇒ Object
50 51 52 |
# File 'lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb', line 50 def with_connection(_args = {}) self end |