sequel-activerecord_connection 1.2.7 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +37 -14
- data/lib/sequel/extensions/activerecord_connection/postgres.rb +8 -3
- data/sequel-activerecord_connection.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b1082cb22dfbf8b9bac60130ae0c37454433f3693fb8ddcb65b5c4acf947c66
|
4
|
+
data.tar.gz: 5bd9aeb196b39ac626e087f88442f42318b628e0d6890761fa071f69efb4b403
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9dd1bc2f3b5e2435e8bf5786955cf6c53ebe26d30d87a283b571fa3c2cb5ad1cef61b99997b3dc480d123636920681a7304d7e3a1a05f7d59cadf6ac56f9334
|
7
|
+
data.tar.gz: 4ce05904e61edb1a245ccdec85aa5bbc21c40af2b7c67d0d877c36d2f40bb9430e3b5a76c7a4f4b183d8a544f97b0fc132653d2d03623fef949fb7eb01beb783
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,18 +1,42 @@
|
|
1
1
|
# sequel-activerecord_connection
|
2
2
|
|
3
|
-
This is
|
4
|
-
|
3
|
+
This is a database extension for [Sequel] that makes it to reuse an existing
|
4
|
+
Active Record connection for database interaction.
|
5
5
|
|
6
|
-
This can be useful if you
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
This can be useful if you want to use a library that uses Sequel (e.g.
|
7
|
+
[Rodauth] or [rom-sql]), or you're transitioning from Active Record to Sequel,
|
8
|
+
or if you just want to use Sequel for more complex queries, and you want to
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
adapters, both native and JDBC (JRuby). There is attempted suppport for [Oracle
|
13
|
+
enhanced] and [SQL Server] Active Record adapters (`oracle` and `tinytds` in
|
14
|
+
Sequel). Other adapters might work too, but their integration hasn't been
|
15
|
+
tested.
|
16
|
+
|
17
|
+
## Why reuse the database connection?
|
18
|
+
|
19
|
+
At first it might appear that, as long as you're fine with the performance
|
20
|
+
impact of your database server having to maintain additional open connections,
|
21
|
+
it would be fine if Sequel had its own database connection. However, there are
|
22
|
+
additional caveats when you try to combine it with Active Record.
|
23
|
+
|
24
|
+
If Sequel and Active Record each have their own connections, then it's not
|
25
|
+
possible to combine their transactions. If we executed a Sequel query inside of
|
26
|
+
an Active Record transaction, that query won't actually be executed inside a
|
27
|
+
database transaction. This is because transactions are tied to the database
|
28
|
+
connection; if one connection opens a transaction, this doesn't affect queries
|
29
|
+
executed on a different connection, even if both connections are used in the
|
30
|
+
same ruby process. With this library, transactions and queries can be
|
31
|
+
seamlessly combined between Active Record and Sequel.
|
32
|
+
|
33
|
+
In Rails context, there are additional considerations for a Sequel connection
|
34
|
+
to play nicely. Connecting and disconnecting would have to go in lockstep with
|
35
|
+
Active Record, to make commands such as `rails db:create` and `rails db:drop`
|
36
|
+
work. You'd also need to find a way for system tests and the app running in the
|
37
|
+
background to share the same database connection, which is something Sequel
|
38
|
+
wasn't designed for. Reusing Active Record's connection means (dis)connecting
|
39
|
+
and sharing between threads is all handled automatically.
|
16
40
|
|
17
41
|
## Installation
|
18
42
|
|
@@ -140,9 +164,8 @@ DB.transaction(auto_savepoint: true) do
|
|
140
164
|
end
|
141
165
|
#>> BEGIN
|
142
166
|
#>> SAVEPOINT active_record_1
|
143
|
-
#>>
|
167
|
+
#>> ROLLBACK TO SAVEPOINT active_record_1
|
144
168
|
#>> COMMIT
|
145
|
-
#>> after commit
|
146
169
|
```
|
147
170
|
|
148
171
|
In case of (a) adding a transaction hook while Active Record holds the
|
@@ -168,13 +191,13 @@ end
|
|
168
191
|
# after a savepoint is released, if the enclosing transaction is not joinable.
|
169
192
|
ActiveRecord::Base.transaction(joinable: false) do
|
170
193
|
DB.transaction do
|
171
|
-
DB.after_commit { puts "after
|
194
|
+
DB.after_commit { puts "after savepoint release" }
|
172
195
|
end
|
173
196
|
end
|
174
197
|
#>> BEGIN
|
175
198
|
#>> SAVEPOINT active_record_1
|
176
199
|
#>> RELEASE SAVEPOINT active_record_1
|
177
|
-
#>> after
|
200
|
+
#>> after savepoint release
|
178
201
|
#>> COMMIT
|
179
202
|
```
|
180
203
|
|
@@ -10,6 +10,11 @@ module Sequel
|
|
10
10
|
|
11
11
|
Utils.add_prepared_statements_cache(conn)
|
12
12
|
|
13
|
+
# compatibility for pg_streaming database extension from sequel_pg gem
|
14
|
+
if defined?(Sequel::Postgres::Streaming) && is_a?(Sequel::Postgres::Streaming)
|
15
|
+
conn.extend(Sequel::Postgres::Streaming::AdapterMethods)
|
16
|
+
end
|
17
|
+
|
13
18
|
yield conn
|
14
19
|
end
|
15
20
|
end
|
@@ -70,11 +75,11 @@ module Sequel
|
|
70
75
|
# yield the results, otherwise, return the number of changed rows.
|
71
76
|
def execute(sql, args = nil)
|
72
77
|
args = args.map { |v| @db.bound_variable_arg(v, self) } if args
|
73
|
-
|
78
|
+
q = check_disconnect_errors { execute_query(sql, args) }
|
74
79
|
|
75
|
-
block_given? ? yield(
|
80
|
+
block_given? ? yield(q) : q.cmd_tuples
|
76
81
|
ensure
|
77
|
-
|
82
|
+
q.clear if q && q.respond_to?(:clear)
|
78
83
|
end
|
79
84
|
|
80
85
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "sequel-activerecord_connection"
|
3
|
-
spec.version = "1.2.
|
3
|
+
spec.version = "1.2.8"
|
4
4
|
spec.authors = ["Janko Marohnić"]
|
5
5
|
spec.email = ["janko.marohnic@gmail.com"]
|
6
6
|
|
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.required_ruby_version = ">= 2.4"
|
13
13
|
|
14
14
|
spec.add_dependency "sequel", "~> 5.38"
|
15
|
+
spec.add_dependency "sequel_pg" unless RUBY_ENGINE == "jruby"
|
15
16
|
spec.add_dependency "activerecord", ">= 4.2", "< 8"
|
16
17
|
spec.add_dependency "after_commit_everywhere", "~> 1.1"
|
17
18
|
|
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.8
|
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-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.38'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sequel_pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: activerecord
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '0'
|
126
140
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
141
|
+
rubygems_version: 3.3.3
|
128
142
|
signing_key:
|
129
143
|
specification_version: 4
|
130
144
|
summary: Allows Sequel to use ActiveRecord connection for database interaction.
|