sequel-activerecord_connection 1.2.0 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee4a6a5b6dcfceb9856ca13e48cd47ce2573f9d5f4d8923518854eb0651c1cb9
4
- data.tar.gz: 18fd0ce3a56b87b102e6534eef4ae478d1a2df10a4aac8ae984fa4069c477493
3
+ metadata.gz: 9d73b44077fae26fe7a6fccac31b4884b377c145c23cfd39f39c70666b71580a
4
+ data.tar.gz: 9db866222fa1aabb42e6b356d3fa04eeb3cf7a4e5982218abbb1002df5fbaefc
5
5
  SHA512:
6
- metadata.gz: dd33df7445d400b75b29782c99f83d1afc8fc93338eeab4fd0196c4281e34fc1df21d12a0e1a8ccd130995527bef95d7b3ca1b9b16f47a33623b750842b68732
7
- data.tar.gz: c4e26c97e37efd8f8415c7c03799bdde385a478384531948b60837d43bb1f09e7a9feb899b2d080aa20d41f6fb152adfe236aaf0447a1140637696baecd1b1a7
6
+ metadata.gz: 01c5c7b4c437cd28b532d9b39bf5598afa47699cdb05cc3cc5ac51efb620c59af3b7936cedcccac999b1ccae8062fa903b2fa56b9b6bc0c2fa3e941cc97dd4fc
7
+ data.tar.gz: 296510c5a357a16bb8b7cafeccac2f28b1b0a59175927b387b80c9684bf8d45921f7c870c39a766d2b190ac30cb3cdba735c2a9b09260a8b3bb9a05c6db2709a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 1.2.4 (2021-09-27)
2
+
3
+ * Allow using with Active Record 7.0 (@janko)
4
+
5
+ * Use `ActiveRecord.default_timezone` on Active Record 7.0 or greater (@janko)
6
+
7
+ ## 1.2.3 (2021-07-17)
8
+
9
+ * Bump `after_commit_everywhere` dependency to `~> 1.0` (@wivarn)
10
+
11
+ ## 1.2.2 (2021-01-11)
12
+
13
+ * Ensure Active Record queries inside a Sequel transaction are typemapped correctly in postgres adapter (@janko)
14
+
15
+ * Fix executing Active Record queries inside a Sequel transaction not working in mysql2 adapter (@janko)
16
+
17
+ ## 1.2.1 (2021-01-10)
18
+
19
+ * Fix original mysql2 query options not being restored after nested `DB#synchronize` calls, e.g. when using Sequel transactions (@janko)
20
+
1
21
  ## 1.2.0 (2020-11-15)
2
22
 
3
23
  * Attempt support for [activerecord-sqlserver-adapter](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter) (@janko)
@@ -6,16 +6,25 @@ module Sequel
6
6
  def synchronize(*)
7
7
  super do |conn|
8
8
  # required for prepared statements
9
- conn.instance_variable_set(:@sequel_default_query_options, conn.query_options.dup)
10
9
  Utils.add_prepared_statements_cache(conn)
11
10
 
12
- conn.query_options.merge!(as: :hash, symbolize_keys: true, cache_rows: false)
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
13
21
 
14
- begin
15
- yield conn
16
- ensure
17
- conn.query_options.replace(conn.instance_variable_get(:@sequel_default_query_options))
18
- end
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))
19
28
  end
20
29
  end
21
30
  end
@@ -10,9 +10,7 @@ module Sequel
10
10
 
11
11
  Utils.add_prepared_statements_cache(conn)
12
12
 
13
- Utils.set_value(conn, :type_map_for_results, PG::TypeMapAllStrings.new) do
14
- yield conn
15
- end
13
+ yield conn
16
14
  end
17
15
  end
18
16
 
@@ -32,20 +30,12 @@ module Sequel
32
30
  module ConnectionMethods
33
31
  # The underlying exception classes to reraise as disconnect errors
34
32
  # instead of regular database errors.
35
- DISCONNECT_ERROR_CLASSES = [IOError, Errno::EPIPE, Errno::ECONNRESET, ::PG::ConnectionBad].freeze
33
+ DISCONNECT_ERROR_CLASSES = Sequel::Postgres::Adapter::DISCONNECT_ERROR_CLASSES
36
34
 
37
35
  # Since exception class based disconnect checking may not work,
38
36
  # also trying parsing the exception message to look for disconnect
39
37
  # errors.
40
- DISCONNECT_ERROR_REGEX = /\A#{Regexp.union([
41
- "ERROR: cached plan must not change result type",
42
- "could not receive data from server",
43
- "no connection to the server",
44
- "connection not open",
45
- "connection is closed",
46
- "terminating connection due to administrator command",
47
- "PQconsumeInput() "
48
- ])}/
38
+ DISCONNECT_ERROR_REGEX = Sequel::Postgres::Adapter::DISCONNECT_ERROR_RE
49
39
 
50
40
  def async_exec_params(sql, args)
51
41
  defined?(super) ? super : async_exec(sql, args)
@@ -92,7 +82,9 @@ module Sequel
92
82
  # Return the PG::Result containing the query results.
93
83
  def execute_query(sql, args)
94
84
  @db.log_connection_yield(sql, self, args) do
95
- args ? async_exec_params(sql, args) : async_exec(sql)
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
96
88
  end
97
89
  end
98
90
  end
@@ -15,8 +15,16 @@ module Sequel
15
15
 
16
16
  Utils.add_prepared_statements_cache(conn)
17
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|
18
26
  Utils.set_value(conn, :results_as_hash, nil) do
19
- yield conn
27
+ super
20
28
  end
21
29
  end
22
30
  end
@@ -13,8 +13,6 @@ module Sequel
13
13
  serializable: :serializable,
14
14
  }
15
15
 
16
- ACTIVERECORD_CALLBACKS = Object.new.extend(AfterCommitEverywhere)
17
-
18
16
  def self.extended(db)
19
17
  db.activerecord_model = ActiveRecord::Base
20
18
  db.opts[:test] = false unless db.opts.key?(:test)
@@ -50,7 +48,7 @@ module Sequel
50
48
 
51
49
  # Match database timezone with Active Record.
52
50
  def timezone
53
- @timezone || ActiveRecord::Base.default_timezone
51
+ @timezone || activerecord_timezone
54
52
  end
55
53
 
56
54
  private
@@ -108,7 +106,7 @@ module Sequel
108
106
  # after_commit_everywhere gem.
109
107
  def add_transaction_hook(conn, type, block)
110
108
  if _trans(conn)[:activerecord]
111
- ACTIVERECORD_CALLBACKS.public_send(type, &block)
109
+ AfterCommitEverywhere.public_send(type, &block)
112
110
  else
113
111
  super
114
112
  end
@@ -120,7 +118,7 @@ module Sequel
120
118
  # after_commit_everywhere gem.
121
119
  def add_savepoint_hook(conn, type, block)
122
120
  if _trans(conn)[:savepoints].last[:activerecord]
123
- ACTIVERECORD_CALLBACKS.public_send(type, &block)
121
+ AfterCommitEverywhere.public_send(type, &block)
124
122
  else
125
123
  super
126
124
  end
@@ -152,6 +150,16 @@ module Sequel
152
150
  &block
153
151
  )
154
152
  end
153
+
154
+ if ActiveRecord::VERSION::MAJOR >= 7
155
+ def activerecord_timezone
156
+ ActiveRecord.default_timezone
157
+ end
158
+ else
159
+ def activerecord_timezone
160
+ ActiveRecord::Base.default_timezone
161
+ end
162
+ end
155
163
  end
156
164
 
157
165
  Database.register_extension(:activerecord_connection, ActiveRecordConnection)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "sequel-activerecord_connection"
3
- spec.version = "1.2.0"
3
+ spec.version = "1.2.4"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
@@ -12,8 +12,8 @@ Gem::Specification.new do |spec|
12
12
  spec.required_ruby_version = ">= 2.3"
13
13
 
14
14
  spec.add_dependency "sequel", "~> 5.16"
15
- spec.add_dependency "activerecord", ">= 4.2", "< 7"
16
- spec.add_dependency "after_commit_everywhere", "~> 0.1.5"
15
+ spec.add_dependency "activerecord", ">= 4.2", "< 7.1"
16
+ spec.add_dependency "after_commit_everywhere", "~> 1.1"
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.2.0
4
+ version: 1.2.4
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: 2020-11-15 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '4.2'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '7'
36
+ version: '7.1'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,21 +43,21 @@ dependencies:
43
43
  version: '4.2'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '7'
46
+ version: '7.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: after_commit_everywhere
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.1.5
53
+ version: '1.1'
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: 0.1.5
60
+ version: '1.1'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: sequel
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ homepage: https://github.com/janko/sequel-activerecord_connection
123
123
  licenses:
124
124
  - MIT
125
125
  metadata: {}
126
- post_install_message:
126
+ post_install_message:
127
127
  rdoc_options: []
128
128
  require_paths:
129
129
  - lib
@@ -138,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.1.4
142
- signing_key:
141
+ rubygems_version: 3.2.15
142
+ signing_key:
143
143
  specification_version: 4
144
144
  summary: Allows Sequel to use ActiveRecord connection for database interaction.
145
145
  test_files: []