sequel-activerecord_connection 1.2.10 → 1.3.0

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: 53c5925926ff3924bcef9f86b9450449c801e260196b9d25b85fefa2ce569239
4
- data.tar.gz: c7b26f34a3b40ea1691f82e28aa1dd83cf598593c2dd96aa4f7ba3f450cd97fd
3
+ metadata.gz: 57e9f74b5adc96221191cb92f1be8b2e2614d2fce446bb43d50fc603e755c3d7
4
+ data.tar.gz: efdb083362ed82dec77628b75161aa913e2ef805a8b3d8bec621aaa2e1a693f7
5
5
  SHA512:
6
- metadata.gz: 29c0ff34e41b468d04b24f0ab17dcea10ff63b562873a63669f137b24eb31c3b78869d35154879719c1bc270bc161893250c29ab22dd89fb45ddd4abc0d0678f
7
- data.tar.gz: 4de28a717d23a9879420c716c81ff7609768f76d224394c254f91b76338f6b7b38399584a63152745e0b4efc165a34e223ca5f113fcc54cdbb65abf92ca9448d
6
+ metadata.gz: 0bf43086bf259333fb61dde411660ea2ba65bb03c2d98e123d63283dff257b970426ffb8494d5cc5b1f1d9c4cc73f6c65140c66e7346e8346d82adb7b20598c2
7
+ data.tar.gz: 83b368227d5620985878b5bdb1bc6a31ceb6a9b3f2c0b87b206126e5dcdbb05bb8a7e6917457f7bb04b37a22abac3c2ba9b6e8468bb4cf3eb27d4011ab17aa3e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.3.0 (2023-04-22)
2
+
3
+ * Clear Active Record query cache after Sequel executes SQL statements (@janko)
4
+
5
+ ## 1.2.11 (2023-01-09)
6
+
7
+ * Raise explicit exception in case of mismatch between Active Record and Sequel adapter (@janko)
8
+
1
9
  ## 1.2.10 (2022-12-13)
2
10
 
3
11
  * Fix incorrect PG type mapping when using prepared statements in Sequel (@janko)
@@ -12,7 +20,7 @@
12
20
 
13
21
  ## 1.2.7 (2022-01-20)
14
22
 
15
- * Require Sequel 3.38+ (@janko)
23
+ * Require Sequel 5.38+ (@janko)
16
24
 
17
25
  ## 1.2.6 (2021-12-26)
18
26
 
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:
@@ -27,6 +27,10 @@ module Sequel
27
27
  conn.query_options.replace(conn.remove_instance_variable(:@sequel_default_query_options))
28
28
  end
29
29
  end
30
+
31
+ def activerecord_connection_class
32
+ ::Mysql2::Client
33
+ end
30
34
  end
31
35
  end
32
36
  end
@@ -39,6 +39,10 @@ module Sequel
39
39
  end
40
40
  end
41
41
 
42
+ def activerecord_connection_class
43
+ ::PG::Connection
44
+ end
45
+
42
46
  # Copy-pasted from Sequel::Postgres::Adapter.
43
47
  module ConnectionMethods
44
48
  # The underlying exception classes to reraise as disconnect errors
@@ -28,6 +28,10 @@ module Sequel
28
28
  end
29
29
  end
30
30
  end
31
+
32
+ def activerecord_connection_class
33
+ ::SQLite3::Database
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -14,6 +14,12 @@ module Sequel
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ private
19
+
20
+ def activerecord_connection_class
21
+ ::TinyTds::Client
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -35,7 +35,13 @@ module Sequel
35
35
  # Avoid calling Sequel's connection pool, instead use Active Record's.
36
36
  def synchronize(*)
37
37
  activerecord_lock do
38
- yield activerecord_connection.raw_connection
38
+ conn = activerecord_connection.raw_connection
39
+
40
+ if activerecord_connection_class && !conn.is_a?(activerecord_connection_class)
41
+ fail Error, "expected Active Record connection to be a #{activerecord_connection_class}, got #{conn.class}"
42
+ end
43
+
44
+ yield conn
39
45
  end
40
46
  end
41
47
 
@@ -51,6 +57,13 @@ module Sequel
51
57
  @timezone || activerecord_timezone
52
58
  end
53
59
 
60
+ # Clear Active Record's query cache after potential data modifications.
61
+ def execute(*)
62
+ super
63
+ ensure
64
+ clear_activerecord_query_cache
65
+ end
66
+
54
67
  private
55
68
 
56
69
  # Synchronizes transaction state with ActiveRecord. Sequel uses this
@@ -130,6 +143,16 @@ module Sequel
130
143
  super
131
144
  end
132
145
 
146
+ if ActiveRecord.version >= Gem::Version.new("7.0")
147
+ def clear_activerecord_query_cache
148
+ activerecord_model.clear_query_caches_for_current_thread
149
+ end
150
+ else
151
+ def clear_activerecord_query_cache
152
+ activerecord_connection.clear_query_cache
153
+ end
154
+ end
155
+
133
156
  # Active Record doesn't guarantee that a single connection can only be used
134
157
  # by one thread at a time, so we need to use locking, which is what Active
135
158
  # Record does internally as well.
@@ -151,6 +174,10 @@ module Sequel
151
174
  activerecord_model.connection
152
175
  end
153
176
 
177
+ def activerecord_connection_class
178
+ # defines in adapter modules
179
+ end
180
+
154
181
  def activerecord_log(sql, &block)
155
182
  ActiveSupport::Notifications.instrument(
156
183
  "sql.active_record",
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.2.10"
3
+ spec.version = "1.3.0"
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.10
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-13 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.3.3
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.