sequel-activerecord_connection 1.4.3 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1459c431ad6f922b5c4400d85ae916e5032cab36a959041362f45817b604919d
4
- data.tar.gz: 667fe2896a48d5d93d16e5c5b00e0d064c43d2687ef077bc9421e3d7869a41b6
3
+ metadata.gz: 8ba58fa3e98dd9f9c7ebe569bc5e7db5311f91820e331c9948c089c7f7db3ff7
4
+ data.tar.gz: 6e6c43ee2add8ca65abd531da15023d23ddcd244ed4fbb2eeef83285cd9eb8d7
5
5
  SHA512:
6
- metadata.gz: c9f5cb40548c059e3319be0088b8a158dd66c18543fd31f1954db8bc848c4ef541ec1f779acc637211d730dfe4a080a805ee477f128474c9894cc6883e10f46d
7
- data.tar.gz: 6068798de2efef62ae54cde36cb2d7abbad316aadc3eba6d5dceae1708e1aec36ec43b51cbeaf0f59609fd2be09e5d02b0f07afde5f646ebf39fb992e054b046
6
+ metadata.gz: ca1724bffc985de2ba03c2f939f0989d141f73ed301c511e0f7cefa86c3f2f5df797ec3c89d128011c4714b946728e6755047d9226ba5afe2d33649ecf76c4cc
7
+ data.tar.gz: 5c19ef6d4814433735ae0b4e42645217346507f5624f4e3f8ca90991dd749955e1cd7dc12dfc7ee9bde7714ecf3ea96acd7ec0be130921f41272b4eeea51a3b7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.5.1 (2024-11-08)
2
+
3
+ * Add support for Active Record 8.0 (@phlipper)
4
+
5
+ ## 1.5.0 (2024-10-16)
6
+
7
+ * Avoid permanent connection checkout on Active Record 7.2+ (@janko)
8
+
1
9
  ## 1.4.3 (2024-09-26)
2
10
 
3
11
  * Fix compatibility with adapters that don't support savepoints (@janko)
data/README.md CHANGED
@@ -8,11 +8,11 @@ This can be useful if you want to use a library that uses Sequel (e.g.
8
8
  or if you just want to use Sequel for more complex queries, and you want to
9
9
  avoid creating new database connections.
10
10
 
11
- It works on ActiveRecord 4.2+ and fully supports PostgresSQL, MySQL and SQLite,
12
- both the native adapters and JDBC (JRuby). The [SQL Server] external adapter is
13
- supported as well (`tinytds` in Sequel), and there is attempted support for
14
- [Oracle enhanced] (`oracle` and in Sequel). Other adapters might work too, but
15
- their integration hasn't been tested.
11
+ It fully supports PostgreSQL, MySQL and SQLite adapters, both the native ones
12
+ and JDBC (JRuby). The [SQL Server] external adapter is supported as well
13
+ (`tinytds` in Sequel), and there is attempted support for [Oracle enhanced]
14
+ (`oracle` and in Sequel). Other adapters might work too, but their integration
15
+ hasn't been tested.
16
16
 
17
17
  ## Why reuse the database connection?
18
18
 
@@ -44,9 +44,9 @@ The only hard dependencies are:
44
44
 
45
45
  * [ActiveRecord](https://github.com/rails/rails/tree/main/activerecord)
46
46
  * [Sequel](https://github.com/jeremyevans/sequel)
47
- * [after_commit_everywhere](https://github.com/Envek/after_commit_everywhere)
47
+ * [after_commit_everywhere](https://github.com/Envek/after_commit_everywhere) (on Active Record 7.1 or older)
48
48
 
49
- ...which means you can use it with any Rack / Ruby based framework:
49
+ ...which means you can use it with any Rack / Ruby based framework:
50
50
  Rails / Roda / Sinatra etc. or even without a framework.
51
51
 
52
52
  ## Installation
@@ -245,19 +245,6 @@ Sequel.postgres(extensions: [:activerecord_connection, :sql_log_normalizer])
245
245
  SELECT accounts.* FROM accounts WHERE accounts.email = ? LIMIT ?
246
246
  ```
247
247
 
248
- Note that the `sql_log_normalizer` extension opens a database connection while
249
- it's being loaded. If you're setting up Sequel in a Rails initializer, you'll
250
- probably want to handle the database not existing, so that commands such as
251
- `rails db:create` continue to work.
252
-
253
- ```rb
254
- DB = Sequel.postgres(extensions: :activerecord_connection)
255
- begin
256
- DB.extension :sql_log_normalizer
257
- rescue ActiveRecord::NoDatabaseError
258
- end
259
- ```
260
-
261
248
  ## Tests
262
249
 
263
250
  You'll first want to run the rake tasks for setting up databases and users:
@@ -25,10 +25,12 @@ module Sequel
25
25
  fail Error, "#{key.inspect} transaction option is currently not supported" if opts.key?(key)
26
26
  end
27
27
 
28
- super
29
- rescue => e
30
- activerecord_connection.clear_cache! if e.class.name == "ActiveRecord::PreparedStatementCacheExpired" && !in_transaction?
31
- raise
28
+ super do |conn|
29
+ yield conn
30
+ rescue => e
31
+ activerecord_connection.clear_cache! if e.class.name == "ActiveRecord::PreparedStatementCacheExpired"
32
+ raise
33
+ end
32
34
  end
33
35
 
34
36
  private
@@ -39,7 +39,7 @@ module Sequel
39
39
 
40
40
  # Avoid calling Sequel's connection pool, instead use Active Record's.
41
41
  def synchronize(*)
42
- activerecord_lock do
42
+ activerecord_synchronize do
43
43
  conn = activerecord_connection.raw_connection
44
44
 
45
45
  if activerecord_connection_class && !conn.is_a?(activerecord_connection_class)
@@ -47,9 +47,9 @@ module Sequel
47
47
  end
48
48
 
49
49
  yield conn
50
+ ensure
51
+ clear_activerecord_query_cache
50
52
  end
51
- ensure
52
- clear_activerecord_query_cache
53
53
  end
54
54
 
55
55
  # Log executed queries into Active Record logger as well.
@@ -140,7 +140,7 @@ module Sequel
140
140
  end
141
141
  end
142
142
 
143
- if ActiveRecord.version >= Gem::Version.new("7.2.0")
143
+ if ActiveRecord.version >= Gem::Version.new("7.2")
144
144
  def activerecord_transaction_callback(type, &block)
145
145
  activerecord_connection.current_transaction.public_send(type, &block)
146
146
  end
@@ -158,6 +158,14 @@ module Sequel
158
158
  super
159
159
  end
160
160
 
161
+ def activerecord_synchronize
162
+ with_activerecord_connection do
163
+ activerecord_lock do
164
+ yield
165
+ end
166
+ end
167
+ end
168
+
161
169
  if ActiveRecord.version >= Gem::Version.new("7.0")
162
170
  def clear_activerecord_query_cache
163
171
  activerecord_model.clear_query_caches_for_current_thread
@@ -168,10 +176,22 @@ module Sequel
168
176
  end
169
177
  end
170
178
 
179
+ if ActiveRecord.version >= Gem::Version.new("7.2")
180
+ def with_activerecord_connection
181
+ activerecord_model.with_connection(prevent_permanent_checkout: true) do
182
+ yield activerecord_connection
183
+ end
184
+ end
185
+ else
186
+ def with_activerecord_connection
187
+ yield activerecord_connection
188
+ end
189
+ end
190
+
171
191
  # Active Record doesn't guarantee that a single connection can only be used
172
192
  # by one thread at a time, so we need to use locking, which is what Active
173
193
  # Record does internally as well.
174
- if ActiveRecord.version >= Gem::Version.new("5.1.0")
194
+ if ActiveRecord.version >= Gem::Version.new("5.1")
175
195
  def activerecord_lock
176
196
  activerecord_connection.lock.synchronize do
177
197
  ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.4.3"
3
+ spec.version = "1.5.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.required_ruby_version = ">= 2.5"
13
13
 
14
14
  spec.add_dependency "sequel", "~> 5.38"
15
- spec.add_dependency "activerecord", ">= 5.0", "< 8"
15
+ spec.add_dependency "activerecord", ">= 5.0", "< 8.1"
16
16
  spec.add_dependency "after_commit_everywhere", "~> 1.1"
17
17
 
18
18
  spec.add_development_dependency "sequel_pg" unless RUBY_ENGINE == "jruby"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-activerecord_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-26 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '5.0'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '8'
36
+ version: '8.1'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '5.0'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '8'
46
+ version: '8.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: after_commit_everywhere
49
49
  requirement: !ruby/object:Gem::Requirement