sequel-activerecord_connection 1.1.0 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +10 -4
- data/lib/sequel/extensions/activerecord_connection.rb +0 -19
- data/lib/sequel/extensions/activerecord_connection/jdbc.rb +5 -1
- data/lib/sequel/extensions/activerecord_connection/mysql2.rb +18 -7
- data/lib/sequel/extensions/activerecord_connection/oracle.rb +16 -0
- data/lib/sequel/extensions/activerecord_connection/postgres.rb +8 -14
- data/lib/sequel/extensions/activerecord_connection/sqlite.rb +11 -1
- data/lib/sequel/extensions/activerecord_connection/tinytds.rb +19 -0
- data/lib/sequel/extensions/activerecord_connection/utils.rb +22 -0
- data/sequel-activerecord_connection.gemspec +2 -2
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0de933805c130dcc42783bcf606f70e99a00346e58286d3bdfbb94ae8922c09
|
4
|
+
data.tar.gz: b60f70b511d83bbac70bcf6a48c99a20af23d58cc6f9d787db0cfccb11a67f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b1f0f3f9f287609eb9f38ea215bdb873624cd4a66ea17c15867ae6a47808902330beaf4c1be09eb459e0b681daffb829812aa7125a4d565aab050e0df4c74ae
|
7
|
+
data.tar.gz: 3647bec71180cf1af65b8379fcfc6eb924b8fffbd4a575a97399e0a9096e77afbc3f1863095c6ce229a05c81b559a2a63a59df91c46cd4bb47d73c10e57c0b4b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 1.2.3 (2021-07-17)
|
2
|
+
|
3
|
+
* Bump `after_commit_everywhere` dependency to `~> 1.0` (@wivarn)
|
4
|
+
|
5
|
+
## 1.2.2 (2021-01-11)
|
6
|
+
|
7
|
+
* Ensure Active Record queries inside a Sequel transaction are typemapped correctly in postgres adapter (@janko)
|
8
|
+
|
9
|
+
* Fix executing Active Record queries inside a Sequel transaction not working in mysql2 adapter (@janko)
|
10
|
+
|
11
|
+
## 1.2.1 (2021-01-10)
|
12
|
+
|
13
|
+
* Fix original mysql2 query options not being restored after nested `DB#synchronize` calls, e.g. when using Sequel transactions (@janko)
|
14
|
+
|
15
|
+
## 1.2.0 (2020-11-15)
|
16
|
+
|
17
|
+
* Attempt support for [activerecord-sqlserver-adapter](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter) (@janko)
|
18
|
+
|
19
|
+
* Attempt support for [oracle-enhanced](https://github.com/rsim/oracle-enhanced) Active Record adapter (@janko)
|
20
|
+
|
1
21
|
## 1.1.0 (2020-11-08)
|
2
22
|
|
3
23
|
* Drop support for Ruby 2.2 (@janko)
|
data/README.md
CHANGED
@@ -9,8 +9,10 @@ separate database connection. Or if you're transitioning from ActiveRecord to
|
|
9
9
|
Sequel, and want the database connection to be shared.
|
10
10
|
|
11
11
|
It works on ActiveRecord 4.2+ and fully supports PostgresSQL, MySQL and SQLite
|
12
|
-
adapters, both the native ones and JDBC (JRuby).
|
13
|
-
|
12
|
+
adapters, both the native ones and JDBC (JRuby). There is attempted suppport
|
13
|
+
for [Oracle enhanced] and [SQL Server] Active Record adapters (`oracle` and
|
14
|
+
`tinytds` in Sequel). Other adapters might work too, but their integration
|
15
|
+
hasn't been tested.
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
@@ -109,8 +111,9 @@ DB.transaction(isolation: :serializable) do
|
|
109
111
|
end
|
110
112
|
```
|
111
113
|
|
112
|
-
When
|
113
|
-
|
114
|
+
When registering transaction hooks, they will be registered on Sequel
|
115
|
+
transactions when possible, in which case they will behave as described in the
|
116
|
+
[Sequel docs][sequel transaction hooks].
|
114
117
|
|
115
118
|
```rb
|
116
119
|
# Sequel: An after_commit transaction hook will always get executed if the outer
|
@@ -223,3 +226,6 @@ Everyone interacting in this project's codebases, issue trackers, chat rooms and
|
|
223
226
|
[Sequel]: https://github.com/jeremyevans/sequel
|
224
227
|
[Rodauth]: https://github.com/jeremyevans/rodauth
|
225
228
|
[rom-sql]: https://github.com/rom-rb/rom-sql
|
229
|
+
[sequel transaction hooks]: http://sequel.jeremyevans.net/rdoc/files/doc/transactions_rdoc.html#label-Transaction+Hooks
|
230
|
+
[Oracle enhanced]: https://github.com/rsim/oracle-enhanced
|
231
|
+
[SQL Server]: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
|
@@ -152,25 +152,6 @@ module Sequel
|
|
152
152
|
&block
|
153
153
|
)
|
154
154
|
end
|
155
|
-
|
156
|
-
module Utils
|
157
|
-
def self.set_value(object, name, new_value)
|
158
|
-
original_value = object.send(name)
|
159
|
-
object.send(:"#{name}=", new_value)
|
160
|
-
yield
|
161
|
-
ensure
|
162
|
-
object.send(:"#{name}=", original_value)
|
163
|
-
end
|
164
|
-
|
165
|
-
def self.add_prepared_statements_cache(conn)
|
166
|
-
return if conn.respond_to?(:prepared_statements)
|
167
|
-
|
168
|
-
class << conn
|
169
|
-
attr_accessor :prepared_statements
|
170
|
-
end
|
171
|
-
conn.prepared_statements = {}
|
172
|
-
end
|
173
|
-
end
|
174
155
|
end
|
175
156
|
|
176
157
|
Database.register_extension(:activerecord_connection, ActiveRecordConnection)
|
@@ -1,19 +1,30 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
1
3
|
module Sequel
|
2
4
|
module ActiveRecordConnection
|
3
5
|
module Mysql2
|
4
6
|
def synchronize(*)
|
5
7
|
super do |conn|
|
6
8
|
# required for prepared statements
|
7
|
-
conn.instance_variable_set(:@sequel_default_query_options, conn.query_options.dup)
|
8
9
|
Utils.add_prepared_statements_cache(conn)
|
9
10
|
|
10
|
-
conn
|
11
|
+
yield conn
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def _execute(conn, sql, opts)
|
18
|
+
if conn.instance_variable_defined?(:@sequel_default_query_options)
|
19
|
+
return super
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
22
|
+
conn.instance_variable_set(:@sequel_default_query_options, conn.query_options.dup)
|
23
|
+
conn.query_options.merge!(as: :hash, symbolize_keys: true, cache_rows: false)
|
24
|
+
begin
|
25
|
+
super
|
26
|
+
ensure
|
27
|
+
conn.query_options.replace(conn.remove_instance_variable(:@sequel_default_query_options))
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module ActiveRecordConnection
|
5
|
+
module Oracle
|
6
|
+
def synchronize(*)
|
7
|
+
super do |conn|
|
8
|
+
# required for prepared statements
|
9
|
+
Utils.add_prepared_statements_cache(conn.raw_oci_connection)
|
10
|
+
|
11
|
+
yield conn.raw_oci_connection
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
1
3
|
module Sequel
|
2
4
|
module ActiveRecordConnection
|
3
5
|
module Postgres
|
@@ -8,9 +10,7 @@ module Sequel
|
|
8
10
|
|
9
11
|
Utils.add_prepared_statements_cache(conn)
|
10
12
|
|
11
|
-
|
12
|
-
yield conn
|
13
|
-
end
|
13
|
+
yield conn
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -30,20 +30,12 @@ module Sequel
|
|
30
30
|
module ConnectionMethods
|
31
31
|
# The underlying exception classes to reraise as disconnect errors
|
32
32
|
# instead of regular database errors.
|
33
|
-
DISCONNECT_ERROR_CLASSES =
|
33
|
+
DISCONNECT_ERROR_CLASSES = Sequel::Postgres::Adapter::DISCONNECT_ERROR_CLASSES
|
34
34
|
|
35
35
|
# Since exception class based disconnect checking may not work,
|
36
36
|
# also trying parsing the exception message to look for disconnect
|
37
37
|
# errors.
|
38
|
-
DISCONNECT_ERROR_REGEX =
|
39
|
-
"ERROR: cached plan must not change result type",
|
40
|
-
"could not receive data from server",
|
41
|
-
"no connection to the server",
|
42
|
-
"connection not open",
|
43
|
-
"connection is closed",
|
44
|
-
"terminating connection due to administrator command",
|
45
|
-
"PQconsumeInput() "
|
46
|
-
])}/
|
38
|
+
DISCONNECT_ERROR_REGEX = Sequel::Postgres::Adapter::DISCONNECT_ERROR_RE
|
47
39
|
|
48
40
|
def async_exec_params(sql, args)
|
49
41
|
defined?(super) ? super : async_exec(sql, args)
|
@@ -90,7 +82,9 @@ module Sequel
|
|
90
82
|
# Return the PG::Result containing the query results.
|
91
83
|
def execute_query(sql, args)
|
92
84
|
@db.log_connection_yield(sql, self, args) do
|
93
|
-
|
85
|
+
Utils.set_value(self, :type_map_for_results, PG::TypeMapAllStrings.new) do
|
86
|
+
args ? async_exec_params(sql, args) : async_exec(sql)
|
87
|
+
end
|
94
88
|
end
|
95
89
|
end
|
96
90
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
1
3
|
module Sequel
|
2
4
|
module ActiveRecordConnection
|
3
5
|
module Sqlite
|
@@ -13,8 +15,16 @@ module Sequel
|
|
13
15
|
|
14
16
|
Utils.add_prepared_statements_cache(conn)
|
15
17
|
|
18
|
+
yield conn
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def _execute(type, sql, opts, &block)
|
25
|
+
synchronize(opts[:server]) do |conn|
|
16
26
|
Utils.set_value(conn, :results_as_hash, nil) do
|
17
|
-
|
27
|
+
super
|
18
28
|
end
|
19
29
|
end
|
20
30
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "utils"
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module ActiveRecordConnection
|
5
|
+
module Tinytds
|
6
|
+
def synchronize(*)
|
7
|
+
super do |conn|
|
8
|
+
conn.query_options.merge!(cache_rows: false)
|
9
|
+
|
10
|
+
begin
|
11
|
+
yield conn
|
12
|
+
ensure
|
13
|
+
conn.query_options.merge!(cache_rows: true)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Sequel
|
2
|
+
module ActiveRecordConnection
|
3
|
+
module Utils
|
4
|
+
def self.set_value(object, name, new_value)
|
5
|
+
original_value = object.send(name)
|
6
|
+
object.send(:"#{name}=", new_value)
|
7
|
+
yield
|
8
|
+
ensure
|
9
|
+
object.send(:"#{name}=", original_value)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.add_prepared_statements_cache(conn)
|
13
|
+
return if conn.respond_to?(:prepared_statements)
|
14
|
+
|
15
|
+
class << conn
|
16
|
+
attr_accessor :prepared_statements
|
17
|
+
end
|
18
|
+
conn.prepared_statements = {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "sequel-activerecord_connection"
|
3
|
-
spec.version = "1.
|
3
|
+
spec.version = "1.2.3"
|
4
4
|
spec.authors = ["Janko Marohnić"]
|
5
5
|
spec.email = ["janko.marohnic@gmail.com"]
|
6
6
|
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
|
14
14
|
spec.add_dependency "sequel", "~> 5.16"
|
15
15
|
spec.add_dependency "activerecord", ">= 4.2", "< 7"
|
16
|
-
spec.add_dependency "after_commit_everywhere", "~>
|
16
|
+
spec.add_dependency "after_commit_everywhere", "~> 1.0"
|
17
17
|
|
18
18
|
spec.add_development_dependency "sequel", "~> 5.38"
|
19
19
|
spec.add_development_dependency "minitest"
|
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.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: '1.0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: '1.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: sequel
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,14 +113,17 @@ files:
|
|
113
113
|
- lib/sequel/extensions/activerecord_connection.rb
|
114
114
|
- lib/sequel/extensions/activerecord_connection/jdbc.rb
|
115
115
|
- lib/sequel/extensions/activerecord_connection/mysql2.rb
|
116
|
+
- lib/sequel/extensions/activerecord_connection/oracle.rb
|
116
117
|
- lib/sequel/extensions/activerecord_connection/postgres.rb
|
117
118
|
- lib/sequel/extensions/activerecord_connection/sqlite.rb
|
119
|
+
- lib/sequel/extensions/activerecord_connection/tinytds.rb
|
120
|
+
- lib/sequel/extensions/activerecord_connection/utils.rb
|
118
121
|
- sequel-activerecord_connection.gemspec
|
119
122
|
homepage: https://github.com/janko/sequel-activerecord_connection
|
120
123
|
licenses:
|
121
124
|
- MIT
|
122
125
|
metadata: {}
|
123
|
-
post_install_message:
|
126
|
+
post_install_message:
|
124
127
|
rdoc_options: []
|
125
128
|
require_paths:
|
126
129
|
- lib
|
@@ -135,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
138
|
- !ruby/object:Gem::Version
|
136
139
|
version: '0'
|
137
140
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
-
signing_key:
|
141
|
+
rubygems_version: 3.2.15
|
142
|
+
signing_key:
|
140
143
|
specification_version: 4
|
141
144
|
summary: Allows Sequel to use ActiveRecord connection for database interaction.
|
142
145
|
test_files: []
|