activerecord-trilogy-adapter 2.0.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: c82a7b7939a81514e90b6c5da24ab8e310a34629cce1c33bd300c1ffa1ca3176
4
- data.tar.gz: 245b8be7fb7fa5672ce6db5598730120c7b401be3e2ec0b3b74fc3ad25592526
3
+ metadata.gz: a64e0395be9ae813e0aec59643758f1a2cc813099c290d95b5c6fbbf8c03746e
4
+ data.tar.gz: 7a1e5be7180c1f84475a40b7a48fe3b717eca0b3c4550ec2e687351049dcfa4e
5
5
  SHA512:
6
- metadata.gz: aa5f9afa69163d02a8d11c75c33c17a0a22a112b7f5ec33671c92b4900b185340665ddc01036a59227ad4e9d8199f86d745ce983dd84c74a54f8e6f3eb6d7538
7
- data.tar.gz: 50496283df9b2dd9f7c23b0131951393696512bc2bb904bfd5b708401c7d8c8e875cec5a9ef1a8beae8869d3533c070a24f9b2b577acc8ad7ec04b1b8e9c67e2
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,30 +56,49 @@ 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
 
71
62
  include DatabaseStatements
72
63
 
64
+ SSL_MODES = {
65
+ SSL_MODE_DISABLED: Trilogy::SSL_DISABLED,
66
+ SSL_MODE_PREFERRED: Trilogy::SSL_PREFERRED_NOVERIFY,
67
+ SSL_MODE_REQUIRED: Trilogy::SSL_REQUIRED_NOVERIFY,
68
+ SSL_MODE_VERIFY_CA: Trilogy::SSL_VERIFY_CA,
69
+ SSL_MODE_VERIFY_IDENTITY: Trilogy::SSL_VERIFY_IDENTITY
70
+ }.freeze
71
+
73
72
  class << self
74
73
  def new_client(config)
74
+ config[:ssl_mode] = parse_ssl_mode(config[:ssl_mode]) if config[:ssl_mode]
75
75
  ::Trilogy.new(config)
76
- rescue Trilogy::DatabaseError => error
76
+ rescue Trilogy::ConnectionError, Trilogy::ProtocolError => error
77
77
  raise translate_connect_error(config, error)
78
78
  end
79
79
 
80
+ def parse_ssl_mode(mode)
81
+ return mode if mode.is_a? Integer
82
+
83
+ m = mode.to_s.upcase
84
+ # enable Mysql2 client compatibility
85
+ m = "SSL_MODE_#{m}" unless m.start_with? "SSL_MODE_"
86
+
87
+ SSL_MODES.fetch(m.to_sym, mode)
88
+ end
89
+
80
90
  def translate_connect_error(config, error)
81
91
  case error.error_code
82
92
  when ER_BAD_DB_ERROR
83
93
  ActiveRecord::NoDatabaseError.db_error(config[:database])
84
94
  when ER_ACCESS_DENIED_ERROR
85
95
  ActiveRecord::DatabaseConnectionError.username_error(config[:username])
86
- when ER_CONN_HOST_ERROR, ER_UNKNOWN_HOST_ERROR
87
- ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
88
96
  else
89
- 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
90
102
  end
91
103
  end
92
104
  end
@@ -116,7 +128,9 @@ module ActiveRecord
116
128
  end
117
129
 
118
130
  def quote_string(string)
119
- any_raw_connection.escape string
131
+ with_raw_connection(allow_retry: true, uses_transaction: false) do |conn|
132
+ conn.escape(string)
133
+ end
120
134
  end
121
135
 
122
136
  def active?
@@ -128,6 +142,7 @@ module ActiveRecord
128
142
  alias reset! reconnect!
129
143
 
130
144
  def disconnect!
145
+ super
131
146
  unless connection.nil?
132
147
  connection.close
133
148
  self.connection = nil
@@ -138,23 +153,6 @@ module ActiveRecord
138
153
  self.connection = nil
139
154
  end
140
155
 
141
- def raw_execute(sql, name, async: false, allow_retry: false, uses_transaction: true)
142
- mark_transaction_written_if_write(sql)
143
-
144
- log(sql, name, async: async) do
145
- with_raw_connection(allow_retry: allow_retry, uses_transaction: uses_transaction) do |conn|
146
- # Sync any changes since connection last established.
147
- if default_timezone == :local
148
- conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
149
- else
150
- conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
151
- end
152
-
153
- conn.query(sql)
154
- end
155
- end
156
- end
157
-
158
156
  def each_hash(result)
159
157
  return to_enum(:each_hash, result) unless block_given?
160
158
 
@@ -191,15 +189,27 @@ module ActiveRecord
191
189
 
192
190
  def reconnect
193
191
  connection&.close
192
+ self.connection = nil
194
193
  connect
195
194
  end
196
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
+
197
205
  def full_version
198
206
  schema_cache.database_version.full_version_string
199
207
  end
200
208
 
201
209
  def get_full_version
202
- any_raw_connection.server_info[:version]
210
+ with_raw_connection(allow_retry: true, uses_transaction: false) do |conn|
211
+ conn.server_info[:version]
212
+ end
203
213
  end
204
214
 
205
215
  def translate_exception(exception, message:, sql:, binds:)
@@ -208,6 +218,10 @@ module ActiveRecord
208
218
  ::TrilogyAdapter::LostConnectionExceptionTranslator.
209
219
  new(exception, message, error_code).translate || super
210
220
  end
221
+
222
+ def default_prepared_statements
223
+ false
224
+ end
211
225
  end
212
226
  end
213
227
  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
@@ -35,10 +35,12 @@ module TrilogyAdapter
35
35
  case exception
36
36
  when Errno::EPIPE
37
37
  Errors::BrokenPipe.new(message)
38
- when SocketError
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.0.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.0.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-08-10 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,28 +16,28 @@ 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
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 7.1.0.alpha
33
+ version: 7.1.a
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 7.1.0.alpha
40
+ version: 7.1.a
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  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
@@ -136,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
135
  - !ruby/object:Gem::Version
137
136
  version: '0'
138
137
  requirements: []
139
- rubygems_version: 3.3.3
138
+ rubygems_version: 3.2.33
140
139
  signing_key:
141
140
  specification_version: 4
142
141
  summary: Active Record adapter for https://github.com/github/trilogy.
@@ -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