fibered_mysql2 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e44e8e3a3b531c9fe568f4d0fcbd19dea85b92e0fc391ca9e50c898b0119359
4
- data.tar.gz: e41214cb8676608ed5ec6a22dbabea0dfa6d02d41e5ec3a78be4ce0057e76817
3
+ metadata.gz: 8cf06a5be94da99bc7d1e0de4b5268ff04a72fd7671e6c4d522186d1ea67dd0b
4
+ data.tar.gz: 931890052763e7fcf2f1ffb7925848004dc54c4c583f89d24c258cbe1537a67a
5
5
  SHA512:
6
- metadata.gz: 3d55a57ce410ccbbbe0c31c08e8dce4f3115ad175ac71cd9747d2072a9771c068c43bfbc05c374631e1f80484619a3adfcee98cfe00eb57fe6458204c538d285
7
- data.tar.gz: 3301cac13fa5c7c2140660e3282f50c06ad3d3bac53a1afe02be328eb5d9e7580e4441e413993fe060a8c1db49d3884c8beafd0295d0dbdc95b9e0113ba1b680
6
+ metadata.gz: 42cab06e4e9bccd07df1436db08c8fb0e8038027690bc03cc58a34eab99ecfd6cccedbdde27f63f9607ce391bea3de8d941cc720775deb7c0c7d65134f405bae
7
+ data.tar.gz: be4a1bd1357e9d51e2e76e48f93ede62f8b7c3cb9cf515a042cf9d10f4d2afe63721349f5afe65a67d2cc9246741aab39a80c7aa903bafde77d95d75c026cd05
@@ -11,8 +11,8 @@ jobs:
11
11
  ruby: [3.1, 3.2, 3.3]
12
12
  gemfile:
13
13
  - Gemfile
14
- - gemfiles/rails_6_0.gemfile
15
14
  - gemfiles/rails_6_1.gemfile
15
+ - gemfiles/rails_7_0.gemfile
16
16
  env:
17
17
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
18
18
  steps:
data/Appraisals CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require "appraisal/matrix"
4
4
 
5
- appraisal_matrix(rails: "~> 6.0")
5
+ appraisal_matrix(rails: [">= 6.1", "< 7.1"])
data/CHANGELOG.md CHANGED
@@ -4,9 +4,24 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.3.1] - 2024-10-30
8
+ ### Fixed
9
+ - Fixed bug in FiberedMysqlAdapter.new_client that was causing `uninitialized constant` errors.
10
+
11
+ ## [0.3.0] - 2024-10-23
12
+ ### Added
13
+ - Support for Rails 7.0.
14
+
15
+ ### Removed
16
+ - Removed support for Rails 6.0 and Rails 5.
17
+
18
+ ### Changed
19
+ - Clean up FiberedMysql2ConnectionFactory#fibered_mysql2_connection to better match Mysql2Adapter behavior.
20
+ - Change FiberedMysql2::FiberedDatabaseConnectionPool#initialize to match ActiveRecord::ConnectionAdapters::ConnectionPool#initialize arguments.
21
+
7
22
  ## [0.2.1] - 2024-08-19
8
23
  ### Fixed
9
- - Fixed bugs in Rails 6.1.
24
+ - Fixed bugs in Rails 6.1
10
25
 
11
26
  ## [0.2.0] - 2023-01-12
12
27
  ### Added
data/Gemfile.lock CHANGED
@@ -1,72 +1,78 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fibered_mysql2 (0.2.1)
4
+ fibered_mysql2 (0.3.1)
5
5
  em-synchrony (~> 1.0)
6
- rails (>= 5.2, < 7)
6
+ rails (>= 6.1, < 7.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (6.1.7.8)
12
- actionpack (= 6.1.7.8)
13
- activesupport (= 6.1.7.8)
11
+ actioncable (7.0.8.6)
12
+ actionpack (= 7.0.8.6)
13
+ activesupport (= 7.0.8.6)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (6.1.7.8)
17
- actionpack (= 6.1.7.8)
18
- activejob (= 6.1.7.8)
19
- activerecord (= 6.1.7.8)
20
- activestorage (= 6.1.7.8)
21
- activesupport (= 6.1.7.8)
16
+ actionmailbox (7.0.8.6)
17
+ actionpack (= 7.0.8.6)
18
+ activejob (= 7.0.8.6)
19
+ activerecord (= 7.0.8.6)
20
+ activestorage (= 7.0.8.6)
21
+ activesupport (= 7.0.8.6)
22
22
  mail (>= 2.7.1)
23
- actionmailer (6.1.7.8)
24
- actionpack (= 6.1.7.8)
25
- actionview (= 6.1.7.8)
26
- activejob (= 6.1.7.8)
27
- activesupport (= 6.1.7.8)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.8.6)
27
+ actionpack (= 7.0.8.6)
28
+ actionview (= 7.0.8.6)
29
+ activejob (= 7.0.8.6)
30
+ activesupport (= 7.0.8.6)
28
31
  mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
29
35
  rails-dom-testing (~> 2.0)
30
- actionpack (6.1.7.8)
31
- actionview (= 6.1.7.8)
32
- activesupport (= 6.1.7.8)
33
- rack (~> 2.0, >= 2.0.9)
36
+ actionpack (7.0.8.6)
37
+ actionview (= 7.0.8.6)
38
+ activesupport (= 7.0.8.6)
39
+ rack (~> 2.0, >= 2.2.4)
34
40
  rack-test (>= 0.6.3)
35
41
  rails-dom-testing (~> 2.0)
36
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
- actiontext (6.1.7.8)
38
- actionpack (= 6.1.7.8)
39
- activerecord (= 6.1.7.8)
40
- activestorage (= 6.1.7.8)
41
- activesupport (= 6.1.7.8)
43
+ actiontext (7.0.8.6)
44
+ actionpack (= 7.0.8.6)
45
+ activerecord (= 7.0.8.6)
46
+ activestorage (= 7.0.8.6)
47
+ activesupport (= 7.0.8.6)
48
+ globalid (>= 0.6.0)
42
49
  nokogiri (>= 1.8.5)
43
- actionview (6.1.7.8)
44
- activesupport (= 6.1.7.8)
50
+ actionview (7.0.8.6)
51
+ activesupport (= 7.0.8.6)
45
52
  builder (~> 3.1)
46
53
  erubi (~> 1.4)
47
54
  rails-dom-testing (~> 2.0)
48
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
- activejob (6.1.7.8)
50
- activesupport (= 6.1.7.8)
56
+ activejob (7.0.8.6)
57
+ activesupport (= 7.0.8.6)
51
58
  globalid (>= 0.3.6)
52
- activemodel (6.1.7.8)
53
- activesupport (= 6.1.7.8)
54
- activerecord (6.1.7.8)
55
- activemodel (= 6.1.7.8)
56
- activesupport (= 6.1.7.8)
57
- activestorage (6.1.7.8)
58
- actionpack (= 6.1.7.8)
59
- activejob (= 6.1.7.8)
60
- activerecord (= 6.1.7.8)
61
- activesupport (= 6.1.7.8)
59
+ activemodel (7.0.8.6)
60
+ activesupport (= 7.0.8.6)
61
+ activerecord (7.0.8.6)
62
+ activemodel (= 7.0.8.6)
63
+ activesupport (= 7.0.8.6)
64
+ activestorage (7.0.8.6)
65
+ actionpack (= 7.0.8.6)
66
+ activejob (= 7.0.8.6)
67
+ activerecord (= 7.0.8.6)
68
+ activesupport (= 7.0.8.6)
62
69
  marcel (~> 1.0)
63
70
  mini_mime (>= 1.1.0)
64
- activesupport (6.1.7.8)
71
+ activesupport (7.0.8.6)
65
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
66
73
  i18n (>= 1.6, < 2)
67
74
  minitest (>= 5.1)
68
75
  tzinfo (~> 2.0)
69
- zeitwerk (~> 2.3)
70
76
  appraisal (2.5.0)
71
77
  bundler
72
78
  rake
@@ -94,10 +100,10 @@ GEM
94
100
  eventmachine (1.2.7)
95
101
  globalid (1.2.1)
96
102
  activesupport (>= 6.1)
97
- i18n (1.14.5)
103
+ i18n (1.14.6)
98
104
  concurrent-ruby (~> 1.0)
99
105
  json (2.7.2)
100
- loofah (2.22.0)
106
+ loofah (2.23.1)
101
107
  crass (~> 1.0.2)
102
108
  nokogiri (>= 1.12.0)
103
109
  mail (2.8.1)
@@ -111,7 +117,7 @@ GEM
111
117
  mini_portile2 (2.8.7)
112
118
  minitest (5.25.1)
113
119
  mysql2 (0.5.6)
114
- net-imap (0.4.14)
120
+ net-imap (0.5.0)
115
121
  date
116
122
  net-protocol
117
123
  net-pop (0.1.2)
@@ -120,7 +126,7 @@ GEM
120
126
  timeout
121
127
  net-smtp (0.5.0)
122
128
  net-protocol
123
- nio4r (2.7.3)
129
+ nio4r (2.7.4)
124
130
  nokogiri (1.16.7)
125
131
  mini_portile2 (~> 2.8.2)
126
132
  racc (~> 1.4)
@@ -131,24 +137,23 @@ GEM
131
137
  byebug (~> 11.0)
132
138
  pry (>= 0.13, < 0.15)
133
139
  racc (1.8.1)
134
- rack (2.2.9)
140
+ rack (2.2.10)
135
141
  rack-test (2.1.0)
136
142
  rack (>= 1.3)
137
- rails (6.1.7.8)
138
- actioncable (= 6.1.7.8)
139
- actionmailbox (= 6.1.7.8)
140
- actionmailer (= 6.1.7.8)
141
- actionpack (= 6.1.7.8)
142
- actiontext (= 6.1.7.8)
143
- actionview (= 6.1.7.8)
144
- activejob (= 6.1.7.8)
145
- activemodel (= 6.1.7.8)
146
- activerecord (= 6.1.7.8)
147
- activestorage (= 6.1.7.8)
148
- activesupport (= 6.1.7.8)
143
+ rails (7.0.8.6)
144
+ actioncable (= 7.0.8.6)
145
+ actionmailbox (= 7.0.8.6)
146
+ actionmailer (= 7.0.8.6)
147
+ actionpack (= 7.0.8.6)
148
+ actiontext (= 7.0.8.6)
149
+ actionview (= 7.0.8.6)
150
+ activejob (= 7.0.8.6)
151
+ activemodel (= 7.0.8.6)
152
+ activerecord (= 7.0.8.6)
153
+ activestorage (= 7.0.8.6)
154
+ activesupport (= 7.0.8.6)
149
155
  bundler (>= 1.15.0)
150
- railties (= 6.1.7.8)
151
- sprockets-rails (>= 2.0.0)
156
+ railties (= 7.0.8.6)
152
157
  rails-dom-testing (2.2.0)
153
158
  activesupport (>= 5.0.0)
154
159
  minitest
@@ -156,12 +161,13 @@ GEM
156
161
  rails-html-sanitizer (1.6.0)
157
162
  loofah (~> 2.21)
158
163
  nokogiri (~> 1.14)
159
- railties (6.1.7.8)
160
- actionpack (= 6.1.7.8)
161
- activesupport (= 6.1.7.8)
164
+ railties (7.0.8.6)
165
+ actionpack (= 7.0.8.6)
166
+ activesupport (= 7.0.8.6)
162
167
  method_source
163
168
  rake (>= 12.2)
164
169
  thor (~> 1.0)
170
+ zeitwerk (~> 2.5)
165
171
  rake (13.2.1)
166
172
  rspec (3.13.0)
167
173
  rspec-core (~> 3.13.0)
@@ -181,17 +187,10 @@ GEM
181
187
  json (>= 1.8, < 3)
182
188
  simplecov-html (~> 0.10.0)
183
189
  simplecov-html (0.10.2)
184
- sprockets (4.2.1)
185
- concurrent-ruby (~> 1.0)
186
- rack (>= 2.2.4, < 4)
187
- sprockets-rails (3.5.2)
188
- actionpack (>= 6.1)
189
- activesupport (>= 6.1)
190
- sprockets (>= 3.0.0)
191
190
  sync (0.5.0)
192
191
  term-ansicolor (1.11.2)
193
192
  tins (~> 1.0)
194
- thor (1.3.1)
193
+ thor (1.3.2)
195
194
  timeout (0.4.1)
196
195
  tins (1.33.0)
197
196
  bigdecimal
@@ -201,7 +200,7 @@ GEM
201
200
  websocket-driver (0.7.6)
202
201
  websocket-extensions (>= 0.1.0)
203
202
  websocket-extensions (0.1.5)
204
- zeitwerk (2.6.17)
203
+ zeitwerk (2.6.18)
205
204
 
206
205
  PLATFORMS
207
206
  ruby
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_dependency 'em-synchrony', '~> 1.0'
33
- spec.add_dependency 'rails', '>= 5.2', '< 7'
33
+ spec.add_dependency 'rails', '>= 6.1', '< 7.1'
34
34
  end
@@ -11,6 +11,6 @@ gem "pry"
11
11
  gem "pry-byebug"
12
12
  gem "rake"
13
13
  gem "rspec"
14
- gem "rails", "~> 6.0.0"
14
+ gem "rails", "~> 7.0.0"
15
15
 
16
16
  gemspec path: "../"
@@ -3,19 +3,10 @@
3
3
  require 'em-synchrony'
4
4
  require 'active_model'
5
5
  require 'active_record/errors'
6
+ require 'active_record/connection_adapters/mysql2_adapter'
6
7
  require 'active_record/connection_adapters/em_mysql2_adapter'
7
8
 
8
9
  module FiberedMysql2
9
- module FiberedMysql2Adapter_4_2
10
- def lease
11
- synchronize do
12
- unless in_use?
13
- @owner = Fiber.current
14
- end
15
- end
16
- end
17
- end
18
-
19
10
  module FiberedMysql2Adapter_5_2
20
11
  def lease
21
12
  if in_use?
@@ -72,11 +63,19 @@ module FiberedMysql2
72
63
  end
73
64
 
74
65
  class FiberedMysql2Adapter < ::ActiveRecord::ConnectionAdapters::EMMysql2Adapter
75
- case ::Rails::VERSION::MAJOR
76
- when 4
77
- include FiberedMysql2Adapter_4_2
78
- when 5, 6
79
- include FiberedMysql2Adapter_5_2
66
+ include FiberedMysql2Adapter_5_2
67
+
68
+ class << self
69
+ # Copied from Mysql2Adapter, except with the EM Mysql2 client
70
+ def new_client(config)
71
+ Mysql2::EM::Client.new(config)
72
+ rescue Mysql2::Error => error
73
+ if error.error_number == 1049
74
+ raise ActiveRecord::NoDatabaseError.new, error.message
75
+ else
76
+ raise ActiveRecord::ConnectionNotEstablished, error.message
77
+ end
78
+ end
80
79
  end
81
80
 
82
81
  def initialize(*args)
@@ -186,25 +186,6 @@ module FiberedMysql2
186
186
  module FiberedDatabaseConnectionPool
187
187
  include FiberedMonitorMixin
188
188
 
189
- module Adapter_4_2
190
- def cached_connections
191
- @reserved_connections
192
- end
193
-
194
- def current_connection_id
195
- ActiveRecord::Base.connection_id ||= Fiber.current.object_id
196
- end
197
-
198
- def checkout
199
- begin
200
- reap_connections
201
- rescue => ex
202
- ActiveRecord::Base.logger.error("Exception occurred while executing reap_connections: #{ex}")
203
- end
204
- super
205
- end
206
- end
207
-
208
189
  module Adapter_5_2
209
190
  def cached_connections
210
191
  @thread_cached_conns
@@ -229,27 +210,16 @@ module FiberedMysql2
229
210
  end
230
211
  end
231
212
  end
213
+ include Adapter_5_2
232
214
 
233
- case Rails::VERSION::MAJOR
234
- when 4
235
- include Adapter_4_2
236
- when 5, 6
237
- include Adapter_5_2
238
- end
239
-
240
- def initialize(connection_spec, *args, **keyword_args)
241
- if ActiveRecord.gem_version < "6.1"
242
- connection_spec.config[:reaping_frequency] and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
243
- connection_spec.config[:reaping_frequency] = nil # starting in Rails 5, this defaults to 60 if not explicitly set
244
- elsif connection_spec.db_config.reaping_frequency
245
- connection_spec.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
215
+ def initialize(pool_config)
216
+ if pool_config.db_config.reaping_frequency
217
+ pool_config.db_config.reaping_frequency > 0 and raise "reaping_frequency is not supported (the ActiveRecord Reaper is thread-based)"
246
218
  end
247
219
 
248
- super(connection_spec, *args, **keyword_args)
220
+ super(pool_config)
249
221
 
250
222
  @reaper = nil # no need to keep a reference to this since it does nothing in this sub-class
251
-
252
- # note that @reserved_connections is a ThreadSafe::Cache which is overkill in a fibered world, but harmless
253
223
  end
254
224
 
255
225
  def connection
@@ -16,90 +16,80 @@ module EM::Synchrony
16
16
 
17
17
  _ = TransactionManager
18
18
  class TransactionManager < _
19
- if Rails::VERSION::MAJOR > 5
20
- # Overriding the em-synchrony override to bring it up to rails 6 requirements.
21
- # Changes from the original Rails 6 source are:
22
- # 1. the usage of _current_stack created by em-synchrony instead of the Rails provided @stack instance variable
23
- # 2. the usage of Fiber.current.object_id as a part of the savepoint transaction name
24
- #
25
- # Original EM Synchrony Source:
26
- # https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/activerecord_4_2.rb#L35-L44
27
- #
28
- # Original Rails Source:
29
- # https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L205-L224
30
- def begin_transaction(options = {})
31
- @connection.lock.synchronize do
32
- run_commit_callbacks = !current_transaction.joinable?
33
- transaction =
34
- if _current_stack.empty?
35
- if ::ActiveRecord.gem_version < "6.1"
36
- ::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, options, run_commit_callbacks: run_commit_callbacks)
37
- else
38
- ::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, **options, run_commit_callbacks: run_commit_callbacks)
39
- end
40
- else
41
- if ::ActiveRecord.gem_version < "6.1"
42
- ::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, options, run_commit_callbacks: run_commit_callbacks)
43
- else
44
- ::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, **options, run_commit_callbacks: run_commit_callbacks)
45
- end
46
- end
47
-
48
- if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && options[:_lazy] != false
49
- @has_unmaterialized_transactions = true
50
- else
51
- transaction.materialize!
52
- end
53
- _current_stack.push(transaction)
54
- transaction
19
+ # Overriding the em-synchrony override to bring it up to rails 6 requirements.
20
+ # Changes from the original Rails 6 source are:
21
+ # 1. the usage of _current_stack created by em-synchrony instead of the Rails provided @stack instance variable
22
+ # 2. the usage of Fiber.current.object_id as a part of the savepoint transaction name
23
+ #
24
+ # Original EM Synchrony Source:
25
+ # https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/activerecord_4_2.rb#L35-L44
26
+ #
27
+ # Original Rails Source:
28
+ # https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/abstract/transaction.rb#L205-L224
29
+ def begin_transaction(isolation: nil, joinable: true, _lazy: true)
30
+ @connection.lock.synchronize do
31
+ run_commit_callbacks = !current_transaction.joinable?
32
+ transaction =
33
+ if _current_stack.empty?
34
+ ::ActiveRecord::ConnectionAdapters::RealTransaction.new(@connection, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
35
+ else
36
+ ::ActiveRecord::ConnectionAdapters::SavepointTransaction.new(@connection, "active_record_#{Fiber.current.object_id}_#{open_transactions}", _current_stack.last, isolation:, joinable:, run_commit_callbacks: run_commit_callbacks)
37
+ end
38
+
39
+ if @connection.supports_lazy_transactions? && lazy_transactions_enabled? && _lazy
40
+ @has_unmaterialized_transactions = true
41
+ else
42
+ transaction.materialize!
55
43
  end
44
+ _current_stack.push(transaction)
45
+ transaction
56
46
  end
47
+ end
57
48
 
58
- # Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
59
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
60
- # transactions.
61
- def materialize_transactions
62
- return if @materializing_transactions
63
- return unless @has_unmaterialized_transactions
64
-
65
- @connection.lock.synchronize do
66
- begin
67
- @materializing_transactions = true
68
- _current_stack.each { |t| t.materialize! unless t.materialized? }
69
- ensure
70
- @materializing_transactions = false
71
- end
72
- @has_unmaterialized_transactions = false
49
+ # Overriding the ActiveRecord::TransactionManager#materialize_transactions method to use
50
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
51
+ # transactions.
52
+ def materialize_transactions
53
+ return if @materializing_transactions
54
+ return unless @has_unmaterialized_transactions
55
+
56
+ @connection.lock.synchronize do
57
+ begin
58
+ @materializing_transactions = true
59
+ _current_stack.each { |t| t.materialize! unless t.materialized? }
60
+ ensure
61
+ @materializing_transactions = false
73
62
  end
63
+ @has_unmaterialized_transactions = false
74
64
  end
65
+ end
75
66
 
76
- # Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
77
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
78
- # transactions.
79
- def commit_transaction
80
- @connection.lock.synchronize do
81
- transaction = _current_stack.last
82
-
83
- begin
84
- transaction.before_commit_records
85
- ensure
86
- _current_stack.pop
87
- end
88
-
89
- transaction.commit
90
- transaction.commit_records
67
+ # Overriding the ActiveRecord::TransactionManager#commit_transaction method to use
68
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
69
+ # transactions.
70
+ def commit_transaction
71
+ @connection.lock.synchronize do
72
+ transaction = _current_stack.last
73
+
74
+ begin
75
+ transaction.before_commit_records
76
+ ensure
77
+ _current_stack.pop
91
78
  end
79
+
80
+ transaction.commit
81
+ transaction.commit_records
92
82
  end
83
+ end
93
84
 
94
- # Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
95
- # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
96
- # transactions.
97
- def rollback_transaction(transaction = nil)
98
- @connection.lock.synchronize do
99
- transaction ||= _current_stack.pop
100
- transaction.rollback
101
- transaction.rollback_records
102
- end
85
+ # Overriding the ActiveRecord::TransactionManager#rollback_transaction method to use
86
+ # fiber safe the _current_stack instead of the @stack instance variable. when marterializing
87
+ # transactions.
88
+ def rollback_transaction(transaction = nil)
89
+ @connection.lock.synchronize do
90
+ transaction ||= _current_stack.pop
91
+ transaction.rollback
92
+ transaction.rollback_records
103
93
  end
104
94
  end
105
95
  end
@@ -111,23 +101,17 @@ module FiberedMysql2
111
101
  module FiberedMysql2ConnectionFactory
112
102
  def fibered_mysql2_connection(raw_config)
113
103
  config = raw_config.symbolize_keys
104
+ config[:flags] ||= 0
114
105
 
106
+ if config[:flags].kind_of? Array
107
+ config[:flags].push "FOUND_ROWS"
108
+ else
109
+ config[:flags] |= Mysql2::Client::FOUND_ROWS
110
+ end
115
111
  config[:username] = 'root' if config[:username].nil?
116
- config[:flags] = Mysql2::Client::FOUND_ROWS if Mysql2::Client.const_defined?(:FOUND_ROWS)
117
-
118
- client =
119
- begin
120
- Mysql2::EM::Client.new(config)
121
- rescue Mysql2::Error => error
122
- if error.message.include?("Unknown database")
123
- raise ActiveRecord::NoDatabaseError.new(error.message, error)
124
- else
125
- raise
126
- end
127
- end
128
112
 
129
- options = [config[:host], config[:username], config[:password], config[:database], config[:port], config[:socket], 0]
130
- FiberedMysql2Adapter.new(client, logger, options, config)
113
+ client = FiberedMysql2Adapter.new_client(config)
114
+ FiberedMysql2Adapter.new(client, logger, nil, config)
131
115
  end
132
116
  end
133
117
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_record/database_configurations/hash_config"
4
+
3
5
  module FiberedMysql2
4
6
  module HashConfigOverride
5
7
  # Override the reaping_frequency method to return nil so that the connection pool does not reap connections when in fibered mode.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiberedMysql2
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fibered_mysql2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-19 00:00:00.000000000 Z
11
+ date: 2024-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-synchrony
@@ -30,20 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.2'
33
+ version: '6.1'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '7'
36
+ version: '7.1'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '5.2'
43
+ version: '6.1'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '7'
46
+ version: '7.1'
47
47
  description:
48
48
  email:
49
49
  - development@invoca.com
@@ -66,8 +66,8 @@ files:
66
66
  - bin/setup
67
67
  - fibered_mysql2.gemspec
68
68
  - gemfiles/.bundle/config
69
- - gemfiles/rails_6_0.gemfile
70
69
  - gemfiles/rails_6_1.gemfile
70
+ - gemfiles/rails_7_0.gemfile
71
71
  - lib/active_record/connection_adapters/fibered_mysql2_adapter.rb
72
72
  - lib/fibered_mysql2.rb
73
73
  - lib/fibered_mysql2/fibered_database_connection_pool.rb