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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +14 -2
- data/lib/sequel/extensions/activerecord_connection/mysql2.rb +4 -0
- data/lib/sequel/extensions/activerecord_connection/postgres.rb +4 -0
- data/lib/sequel/extensions/activerecord_connection/sqlite.rb +4 -0
- data/lib/sequel/extensions/activerecord_connection/tinytds.rb +6 -0
- data/lib/sequel/extensions/activerecord_connection.rb +28 -1
- data/sequel-activerecord_connection.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e9f74b5adc96221191cb92f1be8b2e2614d2fce446bb43d50fc603e755c3d7
|
4
|
+
data.tar.gz: efdb083362ed82dec77628b75161aa913e2ef805a8b3d8bec621aaa2e1a693f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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:
|
@@ -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
|
-
|
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",
|
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
|
+
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:
|
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.
|
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.
|