sequel-activerecord_connection 1.2.9 → 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +53 -18
- data/lib/sequel/extensions/activerecord_connection/mysql2.rb +4 -0
- data/lib/sequel/extensions/activerecord_connection/postgres.rb +13 -3
- 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 +11 -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: 9b0b564099dd7cf0627c98960d7ca34a0fb1682aaa1f5262ee03de9a9bf2ad8a
|
4
|
+
data.tar.gz: 90b84910bae08b57fcc4e3f29deafe07e1e5fb620ae662960c0058a462bc81b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58fd8e6e50e2dc25dba484c1deee60c1f20681761431c4654a3da092572f2cbfb768eb992a7d7e7eb6f03a77691289e3dd5366796c03ecfdefdbf88412bbfa29
|
7
|
+
data.tar.gz: c92338695de7971f16dd4adf3b518bb00f294a033df519fb1b7077c05a3d080cda443c3ac6d245214d2a07d53c7a00c12dbb914de4cda6e8bb74547c6da6541d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.2.11 (2023-01-09)
|
2
|
+
|
3
|
+
* Raise explicit exception in case of mismatch between Active Record and Sequel adapter (@janko)
|
4
|
+
|
5
|
+
## 1.2.10 (2022-12-13)
|
6
|
+
|
7
|
+
* Fix incorrect PG type mapping when using prepared statements in Sequel (@janko)
|
8
|
+
|
1
9
|
## 1.2.9 (2022-03-15)
|
2
10
|
|
3
11
|
* Remove `sequel_pg` and `pg` runtime dependencies introduced in the previous version (@janko)
|
@@ -8,7 +16,7 @@
|
|
8
16
|
|
9
17
|
## 1.2.7 (2022-01-20)
|
10
18
|
|
11
|
-
* Require Sequel
|
19
|
+
* Require Sequel 5.38+ (@janko)
|
12
20
|
|
13
21
|
## 1.2.6 (2021-12-26)
|
14
22
|
|
data/README.md
CHANGED
@@ -9,10 +9,10 @@ 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
11
|
It works on ActiveRecord 4.2+ and fully supports PostgresSQL, MySQL and SQLite
|
12
|
-
adapters, both native and JDBC (JRuby).
|
13
|
-
|
14
|
-
Sequel). Other adapters might work too, but
|
15
|
-
tested.
|
12
|
+
adapters, both native 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.
|
16
16
|
|
17
17
|
## Why reuse the database connection?
|
18
18
|
|
@@ -38,35 +38,36 @@ background to share the same database connection, which is something Sequel
|
|
38
38
|
wasn't designed for. Reusing Active Record's connection means (dis)connecting
|
39
39
|
and sharing between threads is all handled automatically.
|
40
40
|
|
41
|
-
##
|
41
|
+
## Framework Agnostic
|
42
42
|
|
43
|
-
|
43
|
+
The only hard dependencies are:
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
* [ActiveRecord](https://github.com/rails/rails/tree/main/activerecord)
|
46
|
+
* [Sequel](https://github.com/jeremyevans/sequel)
|
47
|
+
* [after_commit_everywhere](https://github.com/Envek/after_commit_everywhere)
|
48
48
|
|
49
|
-
|
49
|
+
...which means you can use it with any Rack / Ruby based framework:
|
50
|
+
Rails / Roda / Sinatra etc. or even without a framework.
|
50
51
|
|
51
|
-
|
52
|
-
$ bundle install
|
53
|
-
```
|
52
|
+
## Installation
|
54
53
|
|
55
|
-
|
54
|
+
Add the gem to your project:
|
56
55
|
|
57
56
|
```sh
|
58
|
-
$
|
57
|
+
$ bundle add sequel-activerecord_connection
|
59
58
|
```
|
60
59
|
|
61
60
|
## Usage
|
62
61
|
|
63
62
|
Assuming you've configured your ActiveRecord connection, you can initialize the
|
64
|
-
appropriate Sequel adapter and load the `activerecord_connection` extension:
|
63
|
+
appropriate Sequel adapter and load the `activerecord_connection` extension: e.g.
|
65
64
|
|
66
65
|
```rb
|
67
|
-
|
66
|
+
# Place in relevant initializer
|
67
|
+
# e.g. Rails: config/initializers/sequel.rb
|
68
68
|
|
69
|
-
|
69
|
+
require "sequel"
|
70
|
+
DB = Sequel.postgres(extensions: :activerecord_connection) # postgres
|
70
71
|
```
|
71
72
|
|
72
73
|
Now any Sequel operations that you make will internaly be done using the
|
@@ -216,6 +217,35 @@ end
|
|
216
217
|
DB.activerecord_model = MyModel
|
217
218
|
```
|
218
219
|
|
220
|
+
### Normalizing SQL logs
|
221
|
+
|
222
|
+
Active Record injects values into queries using bound variables, and displays
|
223
|
+
them at the end of SQL logs:
|
224
|
+
|
225
|
+
```sql
|
226
|
+
SELECT accounts.* FROM accounts WHERE accounts.email = $1 LIMIT $2 [["email", "user@example.com"], ["LIMIT", 1]]
|
227
|
+
```
|
228
|
+
|
229
|
+
Sequel interpolates values into its queries, so by default its SQL logs include
|
230
|
+
them inline:
|
231
|
+
|
232
|
+
```sql
|
233
|
+
SELECT accounts.* FROM accounts WHERE accounts.email = 'user@example.com' LIMIT 1
|
234
|
+
```
|
235
|
+
|
236
|
+
If you want to normalize logs to group similar queries, or you want to protect
|
237
|
+
sensitive data from being stored in the logs, you can use the
|
238
|
+
[sql_log_normalizer] extension to remove literal strings and numbers from
|
239
|
+
logged SQL queries:
|
240
|
+
|
241
|
+
```rb
|
242
|
+
DB = Sequel.postgres(extensions: :activerecord_connection)
|
243
|
+
DB.extension :sql_log_normalizer
|
244
|
+
```
|
245
|
+
```sql
|
246
|
+
SELECT accounts.* FROM accounts WHERE accounts.email = ? LIMIT ?
|
247
|
+
```
|
248
|
+
|
219
249
|
## Tests
|
220
250
|
|
221
251
|
You'll first want to run the rake tasks for setting up databases and users:
|
@@ -238,6 +268,10 @@ $ rake db_teardown_postgres
|
|
238
268
|
$ rake db_teardown_mysql
|
239
269
|
```
|
240
270
|
|
271
|
+
## Support
|
272
|
+
|
273
|
+
Please feel free to raise a new disucssion in [Github issues](https://github.com/janko/sequel-activerecord_connection/discussions), or search amongst the existing questions there.
|
274
|
+
|
241
275
|
## License
|
242
276
|
|
243
277
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -252,3 +286,4 @@ Everyone interacting in this project's codebases, issue trackers, chat rooms and
|
|
252
286
|
[sequel transaction hooks]: http://sequel.jeremyevans.net/rdoc/files/doc/transactions_rdoc.html#label-Transaction+Hooks
|
253
287
|
[Oracle enhanced]: https://github.com/rsim/oracle-enhanced
|
254
288
|
[SQL Server]: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
|
289
|
+
[sql_log_normalizer]: https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/sql_log_normalizer_rb.html
|
@@ -31,6 +31,18 @@ module Sequel
|
|
31
31
|
raise
|
32
32
|
end
|
33
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def _execute(conn, *)
|
37
|
+
Utils.set_value(conn, :type_map_for_results, PG::TypeMapAllStrings.new) do
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def activerecord_connection_class
|
43
|
+
::PG::Connection
|
44
|
+
end
|
45
|
+
|
34
46
|
# Copy-pasted from Sequel::Postgres::Adapter.
|
35
47
|
module ConnectionMethods
|
36
48
|
# The underlying exception classes to reraise as disconnect errors
|
@@ -87,9 +99,7 @@ module Sequel
|
|
87
99
|
# Return the PG::Result containing the query results.
|
88
100
|
def execute_query(sql, args)
|
89
101
|
@db.log_connection_yield(sql, self, args) do
|
90
|
-
|
91
|
-
args ? async_exec_params(sql, args) : async_exec(sql)
|
92
|
-
end
|
102
|
+
args ? async_exec_params(sql, args) : async_exec(sql)
|
93
103
|
end
|
94
104
|
end
|
95
105
|
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
|
-
|
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
|
|
@@ -151,6 +157,10 @@ module Sequel
|
|
151
157
|
activerecord_model.connection
|
152
158
|
end
|
153
159
|
|
160
|
+
def activerecord_connection_class
|
161
|
+
# defines in adapter modules
|
162
|
+
end
|
163
|
+
|
154
164
|
def activerecord_log(sql, &block)
|
155
165
|
ActiveSupport::Notifications.instrument(
|
156
166
|
"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.2.
|
4
|
+
version: 1.2.11
|
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-01-09 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.1
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Allows Sequel to use ActiveRecord connection for database interaction.
|