sequel-activerecord_connection 1.2.11 → 1.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: 9b0b564099dd7cf0627c98960d7ca34a0fb1682aaa1f5262ee03de9a9bf2ad8a
4
- data.tar.gz: 90b84910bae08b57fcc4e3f29deafe07e1e5fb620ae662960c0058a462bc81b2
3
+ metadata.gz: 0e7023579a13396cf034b357786ebf56c98c15a09693ffe97900c86b221cc596
4
+ data.tar.gz: ff4b9033f260499e70a7f82ee901a77a8e370b230e968072c04d9ae5d4226029
5
5
  SHA512:
6
- metadata.gz: 58fd8e6e50e2dc25dba484c1deee60c1f20681761431c4654a3da092572f2cbfb768eb992a7d7e7eb6f03a77691289e3dd5366796c03ecfdefdbf88412bbfa29
7
- data.tar.gz: c92338695de7971f16dd4adf3b518bb00f294a033df519fb1b7077c05a3d080cda443c3ac6d245214d2a07d53c7a00c12dbb914de4cda6e8bb74547c6da6541d
6
+ metadata.gz: ac0955585457b396ffe074ddb6c040adba15b42052d1c1649635c85223b7cee86e11986b639cbe2a868048ab6926d410f5564210ef745101aa880d591242c57d
7
+ data.tar.gz: 459fd7c8b13036b93afe8dfd9a63af1137997ad04fd8e340a9a218c31196ff319dc29861647bfffd9e9a338a21a3cacb88439d04e45fff09f5fa81765167025f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.3.1 (2023-04-22)
2
+
3
+ * Fix Active Record's query cache not being cleared in SQLite adapter (@janko)
4
+
5
+ ## 1.3.0 (2023-04-22)
6
+
7
+ * Clear Active Record query cache after Sequel executes SQL statements (@janko)
8
+
1
9
  ## 1.2.11 (2023-01-09)
2
10
 
3
11
  * Raise explicit exception in case of mismatch between Active Record and Sequel adapter (@janko)
data/README.md CHANGED
@@ -239,13 +239,25 @@ sensitive data from being stored in the logs, you can use the
239
239
  logged SQL queries:
240
240
 
241
241
  ```rb
242
- DB = Sequel.postgres(extensions: :activerecord_connection)
243
- DB.extension :sql_log_normalizer
242
+ Sequel.postgres(extensions: [:activerecord_connection, :sql_log_normalizer])
244
243
  ```
245
244
  ```sql
246
245
  SELECT accounts.* FROM accounts WHERE accounts.email = ? LIMIT ?
247
246
  ```
248
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
+
249
261
  ## Tests
250
262
 
251
263
  You'll first want to run the rake tasks for setting up databases and users:
@@ -57,6 +57,17 @@ module Sequel
57
57
  @timezone || activerecord_timezone
58
58
  end
59
59
 
60
+ # Clear Active Record's query cache after potential data modifications.
61
+ %i[execute_ddl execute_dui execute_insert execute].each do |execute_method|
62
+ define_method(execute_method) do |*args, &block|
63
+ begin
64
+ super(*args, &block)
65
+ ensure
66
+ clear_activerecord_query_cache
67
+ end
68
+ end
69
+ end
70
+
60
71
  private
61
72
 
62
73
  # Synchronizes transaction state with ActiveRecord. Sequel uses this
@@ -136,6 +147,16 @@ module Sequel
136
147
  super
137
148
  end
138
149
 
150
+ if ActiveRecord.version >= Gem::Version.new("7.0")
151
+ def clear_activerecord_query_cache
152
+ activerecord_model.clear_query_caches_for_current_thread
153
+ end
154
+ else
155
+ def clear_activerecord_query_cache
156
+ activerecord_connection.clear_query_cache
157
+ end
158
+ end
159
+
139
160
  # Active Record doesn't guarantee that a single connection can only be used
140
161
  # by one thread at a time, so we need to use locking, which is what Active
141
162
  # Record does internally as well.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.2.11"
3
+ spec.version = "1.3.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
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.2.11
4
+ version: 1.3.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: 2023-01-09 00:00:00.000000000 Z
11
+ date: 2023-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.4.1
141
+ rubygems_version: 3.4.12
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Allows Sequel to use ActiveRecord connection for database interaction.