activerecord-trilogy-adapter 2.1.0 → 2.2.0

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: f6012f06cd5bd29a7bd180354fd0e65c3fd11784a6a7483fac9599d87baa1b68
4
- data.tar.gz: bde2129ca1f647d6b7308c131d00ae012d614ad4aba36450f16fd3551bc303ce
3
+ metadata.gz: a64e0395be9ae813e0aec59643758f1a2cc813099c290d95b5c6fbbf8c03746e
4
+ data.tar.gz: 7a1e5be7180c1f84475a40b7a48fe3b717eca0b3c4550ec2e687351049dcfa4e
5
5
  SHA512:
6
- metadata.gz: 0ae12198df3991bccc1a17a983050457b2483d33f40078d5bd4c99a2d475d5fbdb84a2510c0beb0db65c9ebb4e431e12115ab2830c0cd5901a75cea3dfd7f75a
7
- data.tar.gz: 0aed27beca07c98b513a092345b125129999f5ec0180ee9df0c78b39348c73be71ef0ad78448a644733f8966636f8059ec43aa248b247e66fa7cfda2cb3bdae8
6
+ metadata.gz: b4e7aa7c78d2773783d578708d8267633f006db9f89eba45d58fb172e5fcb8a0bc8b0b4b70542c6cc4900ad0fd217706765db035601b0b862df1bbbf3d79c02e
7
+ data.tar.gz: f508049eb78a987e12c2e18480516b2ffced87c41a8517aaa95a3e24585b2bbb6ae181e1dd4abf8f6889155bf76e351f5912bb74c5deeeff63fce970b303b835
@@ -30,13 +30,6 @@ module ActiveRecord
30
30
  MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
31
31
  end
32
32
 
33
- def execute(sql, name = nil, async: false)
34
- sql = transform_query(sql)
35
- check_if_write_query(sql)
36
-
37
- raw_execute(sql, name, async: async)
38
- end
39
-
40
33
  def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
41
34
  result = execute(sql, name, async: async)
42
35
  ActiveRecord::Result.new(result.fields, result.to_a)
@@ -63,8 +56,6 @@ module ActiveRecord
63
56
 
64
57
  ER_BAD_DB_ERROR = 1049
65
58
  ER_ACCESS_DENIED_ERROR = 1045
66
- ER_CONN_HOST_ERROR = 2003
67
- ER_UNKNOWN_HOST_ERROR = 2005
68
59
 
69
60
  ADAPTER_NAME = "Trilogy"
70
61
 
@@ -82,7 +73,7 @@ module ActiveRecord
82
73
  def new_client(config)
83
74
  config[:ssl_mode] = parse_ssl_mode(config[:ssl_mode]) if config[:ssl_mode]
84
75
  ::Trilogy.new(config)
85
- rescue Trilogy::DatabaseError => error
76
+ rescue Trilogy::ConnectionError, Trilogy::ProtocolError => error
86
77
  raise translate_connect_error(config, error)
87
78
  end
88
79
 
@@ -102,10 +93,12 @@ module ActiveRecord
102
93
  ActiveRecord::NoDatabaseError.db_error(config[:database])
103
94
  when ER_ACCESS_DENIED_ERROR
104
95
  ActiveRecord::DatabaseConnectionError.username_error(config[:username])
105
- when ER_CONN_HOST_ERROR, ER_UNKNOWN_HOST_ERROR
106
- ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
107
96
  else
108
- ActiveRecord::ConnectionNotEstablished.new(error.message)
97
+ if error.message.match?(/TRILOGY_DNS_ERROR/)
98
+ ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
99
+ else
100
+ ActiveRecord::ConnectionNotEstablished.new(error.message)
101
+ end
109
102
  end
110
103
  end
111
104
  end
@@ -149,6 +142,7 @@ module ActiveRecord
149
142
  alias reset! reconnect!
150
143
 
151
144
  def disconnect!
145
+ super
152
146
  unless connection.nil?
153
147
  connection.close
154
148
  self.connection = nil
@@ -159,23 +153,6 @@ module ActiveRecord
159
153
  self.connection = nil
160
154
  end
161
155
 
162
- def raw_execute(sql, name, async: false, allow_retry: false, uses_transaction: true)
163
- mark_transaction_written_if_write(sql)
164
-
165
- log(sql, name, async: async) do
166
- with_raw_connection(allow_retry: allow_retry, uses_transaction: uses_transaction) do |conn|
167
- # Sync any changes since connection last established.
168
- if default_timezone == :local
169
- conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
170
- else
171
- conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
172
- end
173
-
174
- conn.query(sql)
175
- end
176
- end
177
- end
178
-
179
156
  def each_hash(result)
180
157
  return to_enum(:each_hash, result) unless block_given?
181
158
 
@@ -212,9 +189,19 @@ module ActiveRecord
212
189
 
213
190
  def reconnect
214
191
  connection&.close
192
+ self.connection = nil
215
193
  connect
216
194
  end
217
195
 
196
+ def sync_timezone_changes(conn)
197
+ # Sync any changes since connection last established.
198
+ if default_timezone == :local
199
+ conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
200
+ else
201
+ conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
202
+ end
203
+ end
204
+
218
205
  def full_version
219
206
  schema_cache.database_version.full_version_string
220
207
  end
@@ -14,6 +14,10 @@ module TrilogyAdapter
14
14
  # host: "localhost",
15
15
  # database: "demo_development"
16
16
  module Connection
17
+ def trilogy_adapter_class
18
+ ActiveRecord::ConnectionAdapters::TrilogyAdapter
19
+ end
20
+
17
21
  def trilogy_connection(config)
18
22
  configuration = config.dup
19
23
 
@@ -31,7 +35,7 @@ module TrilogyAdapter
31
35
  0
32
36
  ]
33
37
 
34
- ActiveRecord::ConnectionAdapters::TrilogyAdapter.new nil, logger, options, configuration
38
+ trilogy_adapter_class.new nil, logger, options, configuration
35
39
  end
36
40
  end
37
41
  end
@@ -37,8 +37,10 @@ module TrilogyAdapter
37
37
  Errors::BrokenPipe.new(message)
38
38
  when SocketError, IOError
39
39
  Errors::SocketError.new(message)
40
- when Errno::ECONNRESET
41
- Errors::ConnectionResetByPeer.new(message)
40
+ when Trilogy::ConnectionError
41
+ if message.match?(/Connection reset by peer/)
42
+ Errors::ConnectionResetByPeer.new(message)
43
+ end
42
44
  end
43
45
  end
44
46
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrilogyAdapter
4
- VERSION = "2.1.0"
4
+ VERSION = "2.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-trilogy-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-26 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trilogy
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.1
19
+ version: 2.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.1
26
+ version: 2.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +111,6 @@ files:
111
111
  - lib/trilogy_adapter/connection.rb
112
112
  - lib/trilogy_adapter/errors.rb
113
113
  - lib/trilogy_adapter/lost_connection_exception_translator.rb
114
- - lib/trilogy_adapter/rails/dbconsole.rb
115
114
  - lib/trilogy_adapter/railtie.rb
116
115
  - lib/trilogy_adapter/version.rb
117
116
  homepage: https://github.com/github/activerecord-trilogy-adapter
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TrilogyAdapter
4
- module Rails
5
- module DBConsole
6
- class AdapterAdapter < SimpleDelegator
7
- def adapter
8
- "mysql"
9
- end
10
- end
11
-
12
- def db_config
13
- if super.adapter == "trilogy"
14
- AdapterAdapter.new(super)
15
- else
16
- super
17
- end
18
- end
19
- end
20
- end
21
- end