janus-ar 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +67 -59
- data/.gitignore +1 -0
- data/.rubocop.yml +29 -26
- data/Gemfile.lock +142 -125
- data/README.md +130 -131
- data/bin/release.sh +1 -0
- data/gemfiles/activerecord_8_0.gemfile +7 -0
- data/gemfiles/activerecord_8_1.gemfile +7 -0
- data/janus-ar.gemspec +36 -36
- data/lib/janus-ar/active_record/connection_adapters/janus_mysql2_adapter.rb +32 -149
- data/lib/janus-ar/active_record/connection_adapters/janus_trilogy_adapter.rb +32 -149
- data/lib/janus-ar/adapter_extensions.rb +107 -0
- data/lib/janus-ar/context.rb +79 -80
- data/lib/janus-ar/query_director.rb +81 -54
- data/lib/janus-ar/railtie.rb +15 -0
- data/lib/janus-ar/version.rb +17 -17
- data/lib/janus-ar.rb +24 -22
- data/spec/lib/janus-ar/active_record/connection_adapters/janus_mysql_adapter_spec.rb +78 -82
- data/spec/lib/janus-ar/active_record/connection_adapters/janus_trilogy_adapter_spec.rb +77 -82
- data/spec/lib/janus-ar/context_spec.rb +118 -46
- data/spec/lib/janus-ar/db_console_config_spec.rb +28 -0
- data/spec/lib/janus-ar/logging/subscriber_spec.rb +58 -0
- data/spec/lib/janus-ar/query_director_spec.rb +141 -59
- data/spec/shared_examples/a_mysql_like_server.rb +70 -0
- metadata +13 -10
data/README.md
CHANGED
|
@@ -1,131 +1,130 @@
|
|
|
1
|
-
# Janus ActiveRecord
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<img src="assets/janus-logo.png"
|
|
5
|
-
alt="Janus Logo"
|
|
6
|
-
style="float: left; margin: 0 auto; height: 500px;" />
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
> In ancient Roman religion and myth, Janus (/ˈdʒeɪnəs/ JAY-nəs; Latin: Ianvs [ˈi̯aːnʊs]) is the god of beginnings, gates, transitions, time, duality, doorways,[2] passages, frames, and endings. [(wikipedia)](https://en.wikipedia.org/wiki/Janus)
|
|
10
|
-
|
|
11
|
-
[](https://github.com/OLIOEX/janus-ar/actions/workflows/ci.yml)
|
|
12
|
-
[](https://badge.fury.io/rb/janus-ar)
|
|
13
|
-
|
|
14
|
-
Janus ActiveRecord is generic primary/replica proxy for ActiveRecord
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ActiveRecord::ConnectionAdapters.register("
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
* `
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Amazing project logo by @undevelopedbruce.
|
|
1
|
+
# Janus ActiveRecord
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="assets/janus-logo.png"
|
|
5
|
+
alt="Janus Logo"
|
|
6
|
+
style="float: left; margin: 0 auto; height: 500px;" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
> In ancient Roman religion and myth, Janus (/ˈdʒeɪnəs/ JAY-nəs; Latin: Ianvs [ˈi̯aːnʊs]) is the god of beginnings, gates, transitions, time, duality, doorways,[2] passages, frames, and endings. [(wikipedia)](https://en.wikipedia.org/wiki/Janus)
|
|
10
|
+
|
|
11
|
+
[](https://github.com/OLIOEX/janus-ar/actions/workflows/ci.yml)
|
|
12
|
+
[](https://badge.fury.io/rb/janus-ar)
|
|
13
|
+
|
|
14
|
+
Janus ActiveRecord is a generic primary/replica proxy for ActiveRecord 8 and MySQL (via `mysql2` and `trilogy`). It handles the switching of connections between primary and replica database servers. It comes with an ActiveRecord database adapter implementation.
|
|
15
|
+
|
|
16
|
+
Janus is heavily inspired by [Makara](https://github.com/instacart/makara) from TaskRabbit and then Instacart. Unfortunately this project is unmaintained and broke for us with Rails 7.1. This is an attempt to start afresh on the project. It is definitely not as fully featured as Makara at this stage.
|
|
17
|
+
|
|
18
|
+
Learn more about its origins: [https://tech.olioex.com/ruby/2024/04/16/introducing-janus.html](https://tech.olioex.com/ruby/2024/04/16/introducing-janus.html).
|
|
19
|
+
|
|
20
|
+
Notes: the gem requires ActiveRecord `>= 8.0, < 9.0` and Ruby `>= 3.2`, and is tested against MySQL 8.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Use the current version of the gem from [rubygems](https://rubygems.org/gems/janus-ar) in your `Gemfile`.
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
gem 'janus-ar'
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This project assumes that your read/write endpoints are handled by a separate system (e.g. DNS).
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
After a write request during a thread the adapter will continue using the `primary` server, unless the context is specifically released.
|
|
35
|
+
|
|
36
|
+
### Setup
|
|
37
|
+
|
|
38
|
+
#### Rails 7.2+
|
|
39
|
+
|
|
40
|
+
For Rails 7.2 you'll need to manually register the database adaptor in `config/application.rb` after requiring rails but before entering the application configuration, e.g.
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
require 'rails/all'
|
|
44
|
+
|
|
45
|
+
ActiveRecord::ConnectionAdapters.register("janus_trilogy", "ActiveRecord::ConnectionAdapters::JanusTrilogyAdapter", 'janus-ar/active_record/connection_adapters/janus_trilogy_adapter')
|
|
46
|
+
# ...or...
|
|
47
|
+
ActiveRecord::ConnectionAdapters.register("janus_mysql2", "ActiveRecord::ConnectionAdapters::JanusMysql2Adapter", 'janus-ar/active_record/connection_adapters/janus_mysql2_adapter')
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Rails <= 7.1
|
|
51
|
+
|
|
52
|
+
ActiveRecord 7.1 was tested up to releases v0.15.*. After this release we only tested Rails 7.2+. This does not mean it is not compatible, just not tested.
|
|
53
|
+
|
|
54
|
+
### Configuration
|
|
55
|
+
|
|
56
|
+
Update your **database.yml** as follows:
|
|
57
|
+
|
|
58
|
+
```yml
|
|
59
|
+
development:
|
|
60
|
+
adapter: janus_mysql2
|
|
61
|
+
database: database_name
|
|
62
|
+
janus:
|
|
63
|
+
primary:
|
|
64
|
+
<<: *default
|
|
65
|
+
host: primary-host.local
|
|
66
|
+
replica:
|
|
67
|
+
<<: *default
|
|
68
|
+
password: ithappenstobedifferent
|
|
69
|
+
host: replica-host.local
|
|
70
|
+
```
|
|
71
|
+
Note: For `trilogy` please use adapter "janus_trilogy". You'll probably need to add the following to your configuration to have it connect:
|
|
72
|
+
|
|
73
|
+
```yml
|
|
74
|
+
ssl: true
|
|
75
|
+
ssl_mode: 'REQUIRED'
|
|
76
|
+
tls_min_version: 3
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`tls_min_version` here refers to TLS1.2.
|
|
80
|
+
|
|
81
|
+
Otherwise you will get an error like the following (see https://github.com/trilogy-libraries/trilogy/issues/26):
|
|
82
|
+
> trilogy_auth_recv: caching_sha2_password requires either TCP with TLS or a unix socket: TRILOGY_UNSUPPORTED"
|
|
83
|
+
|
|
84
|
+
### Forcing connections
|
|
85
|
+
|
|
86
|
+
A context is local to the current unit of work (thread or fiber, following ActiveRecord's configured isolation level). This allows you to stick to the primary safely within a single request or job, in systems such as Sidekiq for instance.
|
|
87
|
+
|
|
88
|
+
#### Releasing stuck connections (clearing context)
|
|
89
|
+
|
|
90
|
+
In a Rails application the context is released automatically at the start of every unit of work wrapped by the Rails executor — web requests, ActiveJob and Sidekiq-on-Rails jobs — so stickiness from a write never leaks into the next request on a reused thread. You do not need to do anything for this.
|
|
91
|
+
|
|
92
|
+
Outside of Rails (or to clear the context manually), call:
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
Janus::Context.release_all
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Forcing connection to primary server
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
Janus::Context.stick_to_primary
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Logging
|
|
105
|
+
|
|
106
|
+
You can set a logger instance to `::Janus::Logging::Logger.logger`:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
Janus::Logging::Logger.logger = ::Logger.new(STDOUT)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
If using `ActiveRecord` logging, Janus will append the name of the connection used to any logs e.g. `[primary]` or `[replica]`.
|
|
113
|
+
|
|
114
|
+
### What queries goes where?
|
|
115
|
+
|
|
116
|
+
In general: Any `SELECT` statements will execute against your replica(s), anything else will go to the primary.
|
|
117
|
+
|
|
118
|
+
There are some edge cases:
|
|
119
|
+
* `SET` operations will be sent to all connections
|
|
120
|
+
* Execution of specific methods such as `connect!`, `disconnect!`, `reconnect!`, and `clear_cache!` are invoked on all underlying connections
|
|
121
|
+
* Calls inside a transaction will always be sent to the primary (otherwise changes from within the transaction could not be read back on most transaction isolation levels)
|
|
122
|
+
* Locking reads (e.g. `SELECT ... FOR UPDATE`) will always be sent to the primary
|
|
123
|
+
|
|
124
|
+
# Notes
|
|
125
|
+
|
|
126
|
+
Janus does not support Rails' read/write split or sharding using `with_connection`.
|
|
127
|
+
|
|
128
|
+
# Acknowlegements
|
|
129
|
+
|
|
130
|
+
Amazing project logo by @undevelopedbruce.
|
data/bin/release.sh
CHANGED
data/janus-ar.gemspec
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require File.expand_path('lib/janus-ar/version.rb', __dir__)
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |gem|
|
|
6
|
-
gem.authors = ['Lloyd Watkin']
|
|
7
|
-
gem.email = ['lloyd@olioex.com']
|
|
8
|
-
gem.description = 'Read/Write proxy for ActiveRecord using primary/replica databases'
|
|
9
|
-
gem.summary = 'Read/Write proxy for ActiveRecord using primary/replica databases'
|
|
10
|
-
gem.homepage = 'https://github.com/olioex/janus-ar'
|
|
11
|
-
gem.licenses = %w(MIT)
|
|
12
|
-
gem.metadata = {
|
|
13
|
-
'source_code_uri' => 'https://github.com/olioex/janus-ar',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
|
17
|
-
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
|
-
gem.name = 'janus-ar'
|
|
19
|
-
gem.require_paths = %w(lib)
|
|
20
|
-
gem.version = Janus::VERSION
|
|
21
|
-
|
|
22
|
-
gem.required_ruby_version = '>= 3.2.0'
|
|
23
|
-
|
|
24
|
-
gem.add_dependency 'activerecord', '>= 8.0', '< 9.0'
|
|
25
|
-
gem.add_development_dependency 'activesupport', '>= 8.0'
|
|
26
|
-
gem.add_development_dependency 'mysql2'
|
|
27
|
-
gem.add_development_dependency 'trilogy'
|
|
28
|
-
gem.add_development_dependency 'pry'
|
|
29
|
-
gem.add_development_dependency 'rake'
|
|
30
|
-
gem.add_development_dependency 'rspec', '~> 3'
|
|
31
|
-
gem.add_development_dependency 'rubocop', '~> 1.
|
|
32
|
-
gem.add_development_dependency 'rubocop-rails', '~> 2.
|
|
33
|
-
gem.add_development_dependency 'rubocop-rspec'
|
|
34
|
-
gem.add_development_dependency 'rubocop-thread_safety'
|
|
35
|
-
gem.add_development_dependency 'rubocop-performance'
|
|
36
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('lib/janus-ar/version.rb', __dir__)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.authors = ['Lloyd Watkin']
|
|
7
|
+
gem.email = ['lloyd@olioex.com']
|
|
8
|
+
gem.description = 'Read/Write proxy for ActiveRecord using primary/replica databases'
|
|
9
|
+
gem.summary = 'Read/Write proxy for ActiveRecord using primary/replica databases'
|
|
10
|
+
gem.homepage = 'https://github.com/olioex/janus-ar'
|
|
11
|
+
gem.licenses = %w(MIT)
|
|
12
|
+
gem.metadata = {
|
|
13
|
+
'source_code_uri' => 'https://github.com/olioex/janus-ar',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
|
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
|
+
gem.name = 'janus-ar'
|
|
19
|
+
gem.require_paths = %w(lib)
|
|
20
|
+
gem.version = Janus::VERSION
|
|
21
|
+
|
|
22
|
+
gem.required_ruby_version = '>= 3.2.0'
|
|
23
|
+
|
|
24
|
+
gem.add_dependency 'activerecord', '>= 8.0', '< 9.0'
|
|
25
|
+
gem.add_development_dependency 'activesupport', '>= 8.0'
|
|
26
|
+
gem.add_development_dependency 'mysql2'
|
|
27
|
+
gem.add_development_dependency 'trilogy'
|
|
28
|
+
gem.add_development_dependency 'pry'
|
|
29
|
+
gem.add_development_dependency 'rake'
|
|
30
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
|
31
|
+
gem.add_development_dependency 'rubocop', '~> 1.88.0'
|
|
32
|
+
gem.add_development_dependency 'rubocop-rails', '~> 2.35.2'
|
|
33
|
+
gem.add_development_dependency 'rubocop-rspec'
|
|
34
|
+
gem.add_development_dependency 'rubocop-thread_safety'
|
|
35
|
+
gem.add_development_dependency 'rubocop-performance'
|
|
36
|
+
end
|
|
@@ -1,149 +1,32 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'active_record/connection_adapters/abstract_adapter'
|
|
4
|
-
require 'active_record/connection_adapters/mysql2_adapter'
|
|
5
|
-
require_relative '../../../janus-ar'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
super(connection_config, options)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def initialize(*args)
|
|
39
|
-
args[0][:janus]['replica']['database'] = args[0][:database]
|
|
40
|
-
args[0][:janus]['primary']['database'] = args[0][:database]
|
|
41
|
-
|
|
42
|
-
@replica_config = args[0][:janus]['replica']
|
|
43
|
-
args[0] = args[0][:janus]['primary']
|
|
44
|
-
|
|
45
|
-
super(*args)
|
|
46
|
-
@connection_parameters ||= args[0]
|
|
47
|
-
update_config
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def with_connection(_args = {})
|
|
51
|
-
self
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def raw_execute(sql, name = nil, binds = [], prepare: false, async: false, allow_retry: false,
|
|
55
|
-
materialize_transactions: true, batch: false)
|
|
56
|
-
case where_to_send?(sql)
|
|
57
|
-
when :all
|
|
58
|
-
send_to_replica(sql, connection: :all, method: :raw_execute)
|
|
59
|
-
super
|
|
60
|
-
when :replica
|
|
61
|
-
send_to_replica(sql, connection: :replica, method: :raw_execute)
|
|
62
|
-
else
|
|
63
|
-
Janus::Context.stick_to_primary if write_query?(sql)
|
|
64
|
-
Janus::Context.used_connection(:primary)
|
|
65
|
-
super
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def execute(sql)
|
|
70
|
-
case where_to_send?(sql)
|
|
71
|
-
when :all
|
|
72
|
-
send_to_replica(sql, connection: :all, method: :execute)
|
|
73
|
-
super(sql)
|
|
74
|
-
when :replica
|
|
75
|
-
send_to_replica(sql, connection: :replica, method: :execute)
|
|
76
|
-
else
|
|
77
|
-
Janus::Context.stick_to_primary if write_query?(sql)
|
|
78
|
-
Janus::Context.used_connection(:primary)
|
|
79
|
-
super(sql)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def execute_and_free(sql, name = nil, async: false)
|
|
84
|
-
case where_to_send?(sql)
|
|
85
|
-
when :all
|
|
86
|
-
send_to_replica(sql, connection: :all, method: :execute)
|
|
87
|
-
super(sql, name, async:)
|
|
88
|
-
when :replica
|
|
89
|
-
send_to_replica(sql, connection: :replica, method: :execute)
|
|
90
|
-
else
|
|
91
|
-
Janus::Context.stick_to_primary if write_query?(sql)
|
|
92
|
-
Janus::Context.used_connection(:primary)
|
|
93
|
-
super(sql, name, async:)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def connect!(...)
|
|
98
|
-
replica_connection.connect!(...)
|
|
99
|
-
super
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def reconnect!(...)
|
|
103
|
-
replica_connection.reconnect!(...)
|
|
104
|
-
super
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def disconnect!(...)
|
|
108
|
-
replica_connection.disconnect!(...)
|
|
109
|
-
super
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def clear_cache!(...)
|
|
113
|
-
replica_connection.clear_cache!(...)
|
|
114
|
-
super
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def replica_connection
|
|
118
|
-
@replica_connection ||= ActiveRecord::ConnectionAdapters::Mysql2Adapter.new(@replica_config)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
private
|
|
122
|
-
|
|
123
|
-
def where_to_send?(sql)
|
|
124
|
-
Janus::QueryDirector.new(sql, open_transactions).where_to_send?
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def send_to_replica(sql, connection: nil, method: :exec_query)
|
|
128
|
-
Janus::Context.used_connection(connection) if connection
|
|
129
|
-
if method == :execute
|
|
130
|
-
replica_connection.execute(sql)
|
|
131
|
-
elsif method == :raw_execute
|
|
132
|
-
replica_connection.execute(sql)
|
|
133
|
-
else
|
|
134
|
-
replica_connection.exec_query(sql)
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def update_config
|
|
139
|
-
@config[:flags] ||= 0
|
|
140
|
-
|
|
141
|
-
if @config[:flags].is_a? Array
|
|
142
|
-
@config[:flags].push FOUND_ROWS
|
|
143
|
-
else
|
|
144
|
-
@config[:flags] |= ::Janus::Client::FOUND_ROWS
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_record/connection_adapters/abstract_adapter'
|
|
4
|
+
require 'active_record/connection_adapters/mysql2_adapter'
|
|
5
|
+
require_relative '../../../janus-ar'
|
|
6
|
+
require_relative '../../adapter_extensions'
|
|
7
|
+
|
|
8
|
+
module ActiveRecord
|
|
9
|
+
module ConnectionHandling
|
|
10
|
+
def janus_mysql2_connection(config)
|
|
11
|
+
ActiveRecord::ConnectionAdapters::JanusMysql2Adapter.new(config)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Base
|
|
16
|
+
def self.janus_mysql2_adapter_class
|
|
17
|
+
ActiveRecord::ConnectionAdapters::JanusMysql2Adapter
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module ConnectionAdapters
|
|
22
|
+
class JanusMysql2Adapter < ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
23
|
+
include Janus::AdapterExtensions
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def replica_adapter_class
|
|
28
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|