sequel-activerecord_connection 1.2.9 → 1.2.10
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 +4 -0
- data/README.md +53 -18
- data/lib/sequel/extensions/activerecord_connection/postgres.rb +9 -3
- data/sequel-activerecord_connection.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53c5925926ff3924bcef9f86b9450449c801e260196b9d25b85fefa2ce569239
|
4
|
+
data.tar.gz: c7b26f34a3b40ea1691f82e28aa1dd83cf598593c2dd96aa4f7ba3f450cd97fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c0ff34e41b468d04b24f0ab17dcea10ff63b562873a63669f137b24eb31c3b78869d35154879719c1bc270bc161893250c29ab22dd89fb45ddd4abc0d0678f
|
7
|
+
data.tar.gz: 4de28a717d23a9879420c716c81ff7609768f76d224394c254f91b76338f6b7b38399584a63152745e0b4efc165a34e223ca5f113fcc54cdbb65abf92ca9448d
|
data/CHANGELOG.md
CHANGED
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,14 @@ 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
|
+
|
34
42
|
# Copy-pasted from Sequel::Postgres::Adapter.
|
35
43
|
module ConnectionMethods
|
36
44
|
# The underlying exception classes to reraise as disconnect errors
|
@@ -87,9 +95,7 @@ module Sequel
|
|
87
95
|
# Return the PG::Result containing the query results.
|
88
96
|
def execute_query(sql, args)
|
89
97
|
@db.log_connection_yield(sql, self, args) do
|
90
|
-
|
91
|
-
args ? async_exec_params(sql, args) : async_exec(sql)
|
92
|
-
end
|
98
|
+
args ? async_exec_params(sql, args) : async_exec(sql)
|
93
99
|
end
|
94
100
|
end
|
95
101
|
end
|
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.10
|
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-
|
11
|
+
date: 2022-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|