activerecord-trilogy-adapter 3.0.0 → 3.1.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: 778687330e4ff0e83f8cf02ea27808b9e7197c625312611c0dd004d17627a29e
4
- data.tar.gz: f3ddf11ab50accd31b5bd3a4b41899a781f4ac04555739d1e65eff3e884b8b38
3
+ metadata.gz: 065e502503fb93e0e951b03e67c43b8ea257a01c681c077b5b904a95ddcb0c90
4
+ data.tar.gz: 2a85e79e0654196e0dba708f7bbc4146c413bf0f0b135894357bc174374c76fd
5
5
  SHA512:
6
- metadata.gz: 7b2e8b370f301aeda40bef4e1a66c16dc0351b245a5c967341a22e1ab05830e4e11d5cd1de2de2e38a246cbd5fb492e27d8e906770d4484707512a34e9d8430c
7
- data.tar.gz: 3471e795e4942858134083a06f632da5afebb69c60a87001631486c79ecb81dc3f90e5c5cbdf5eb408c48ca125f47055ca8c08c0af945324e1043aa7996b104e
6
+ metadata.gz: 7ed2509f2e8593d3d1b73c56b403875a1751f50c5e5ae99fc405fead7020ec43c5b9e0510e196b3818a5cc1335480062a8c75e2cfebb757ca19c46fa9d1404be
7
+ data.tar.gz: 45d9e001bee0aa227b2e7a7ac2f3b009d009f312cc2af128d5be0275c5f9ff2ce7b496ebde2ca7df1fedfd7a9a6b235df9fef1cfaf2309ca374357ba14d0a485
data/README.md CHANGED
@@ -1,27 +1,34 @@
1
1
  # Trilogy Adapter
2
2
 
3
- Active Record database adapter for [Trilogy](https://github.com/trilogy-libraries/trilogy)
3
+ Ruby on Rails Active Record database adapter for [Trilogy](https://github.com/trilogy-libraries/trilogy), a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.
4
4
 
5
- This gem offers Trilogy support for versions of ActiveRecord prior to 7.1. Currently supports:
5
+ This gem offers Trilogy support for versions of Active Record prior to v7.1. Currently supports:
6
6
 
7
- - Rails v7.0.x
7
+ - ⚠️ Rails v7.1+ includes Trilogy support by default making this gem unnecessary
8
+ - ✅ Rails v7.0.x
9
+ - ✅ Rails v6.1.x
10
+ - ✅ Rails v6.0.x
8
11
 
9
12
  ## Requirements
10
13
 
11
- - [Ruby](https://www.ruby-lang.org) 2.7 or higher
12
- - [Active Record](https://github.com/rails/rails) 7.0.x
13
- - [Trilogy](https://github.com/trilogy-libraries/trilogy) 2.4.0 or higher
14
+ - [Ruby](https://www.ruby-lang.org) v2.7 or higher
15
+ - [Active Record](https://github.com/rails/rails) v6.0.x or higher
16
+ - [Trilogy](https://github.com/trilogy-libraries/trilogy) v2.4.0 or higher, which is included as a dependency of this gem.
14
17
 
15
18
  ## Setup
16
19
 
17
- * Add the following to your Gemfile:
20
+ 1. Add the following to your `Gemfile` and run `bundle install`:
18
21
 
19
- ```rb
20
- gem "activerecord-trilogy-adapter"
21
- ```
22
+ ```rb
23
+ # Gemfile
24
+ gem "activerecord-trilogy-adapter"
25
+ ```
26
+ 2. Update your application's database configuration to use `trilogy` as the adapter:
22
27
 
23
- * Update your database configuration (e.g. `config/database.yml`) to use
24
- `trilogy` as the adapter.
28
+ ```yaml
29
+ # config/database.yml
30
+ adapter: trilogy
31
+ ```
25
32
 
26
33
  ## Versioning
27
34
 
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module Trilogy
6
+ module DatabaseStatements
7
+ READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
8
+ :desc, :describe, :set, :show, :use
9
+ ) # :nodoc:
10
+ private_constant :READ_QUERY
11
+
12
+ HIGH_PRECISION_CURRENT_TIMESTAMP = Arel.sql("CURRENT_TIMESTAMP(6)").freeze # :nodoc:
13
+ private_constant :HIGH_PRECISION_CURRENT_TIMESTAMP
14
+
15
+ def write_query?(sql) # :nodoc:
16
+ !READ_QUERY.match?(sql)
17
+ rescue ArgumentError # Invalid encoding
18
+ !READ_QUERY.match?(sql.b)
19
+ end
20
+
21
+ def explain(arel, binds = [])
22
+ sql = "EXPLAIN #{to_sql(arel, binds)}"
23
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
24
+ result = internal_exec_query(sql, "EXPLAIN", binds)
25
+ elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
26
+
27
+ MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
28
+ end
29
+
30
+ def select_all(*, **) # :nodoc:
31
+ result = super
32
+ with_trilogy_connection do |conn|
33
+ conn.next_result while conn.more_results_exist?
34
+ end
35
+ result
36
+ end
37
+
38
+ def exec_query(sql, name = "SQL", binds = [], prepare: false, **kwargs)
39
+ internal_exec_query(sql, name, binds, prepare: prepare, **kwargs)
40
+ end
41
+
42
+ def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) # :nodoc:
43
+ sql = transform_query(sql)
44
+ check_if_write_query(sql)
45
+ mark_transaction_written_if_write(sql)
46
+
47
+ result = raw_execute(sql, name, async: async)
48
+ ActiveRecord::Result.new(result.fields, result.to_a)
49
+ end
50
+
51
+ def exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) # :nodoc:
52
+ sql = transform_query(sql)
53
+ check_if_write_query(sql)
54
+ mark_transaction_written_if_write(sql)
55
+
56
+ raw_execute(to_sql(sql, binds), name)
57
+ end
58
+
59
+ def exec_delete(sql, name = nil, binds = []) # :nodoc:
60
+ sql = transform_query(sql)
61
+ check_if_write_query(sql)
62
+ mark_transaction_written_if_write(sql)
63
+
64
+ result = raw_execute(to_sql(sql, binds), name)
65
+ result.affected_rows
66
+ end
67
+
68
+ alias :exec_update :exec_delete # :nodoc:
69
+
70
+ def high_precision_current_timestamp
71
+ HIGH_PRECISION_CURRENT_TIMESTAMP
72
+ end
73
+
74
+ private
75
+ if ActiveRecord.version < ::Gem::Version.new('7.0.a') # ActiveRecord <= 6.1 support
76
+ def raw_execute(sql, name, uses_transaction: true, **_kwargs)
77
+ # Same as mark_transaction_written_if_write(sql)
78
+ transaction = current_transaction
79
+ if transaction.respond_to?(:written) && transaction.open?
80
+ transaction.written ||= write_query?(sql)
81
+ end
82
+
83
+ log(sql, name) do
84
+ with_trilogy_connection(uses_transaction: uses_transaction) do |conn|
85
+ sync_timezone_changes(conn)
86
+ conn.query(sql)
87
+ end
88
+ end
89
+ end
90
+
91
+ def transform_query(sql); sql; end
92
+ def check_if_write_query(*args); end
93
+
94
+ if ActiveRecord.version < ::Gem::Version.new('6.1.a') # ActiveRecord <= 6.0 support
95
+ def mark_transaction_written_if_write(*args); end
96
+ end
97
+ else # ActiveRecord 7.0 support
98
+ def raw_execute(sql, name, uses_transaction: true, async: false, allow_retry: false)
99
+ mark_transaction_written_if_write(sql)
100
+ log(sql, name, async: async) do
101
+ with_trilogy_connection(uses_transaction: uses_transaction, allow_retry: allow_retry) do |conn|
102
+ sync_timezone_changes(conn)
103
+ conn.query(sql)
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ def last_inserted_id(result)
110
+ result.last_insert_id
111
+ end
112
+
113
+ def sync_timezone_changes(conn)
114
+ # Sync any changes since connection last established.
115
+ if default_timezone == :local
116
+ conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
117
+ else
118
+ conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -4,83 +4,82 @@ require "trilogy"
4
4
  require "active_record/connection_adapters/abstract_mysql_adapter"
5
5
 
6
6
  require "active_record/tasks/trilogy_database_tasks"
7
+ require "active_record/connection_adapters/trilogy/database_statements"
7
8
  require "trilogy_adapter/lost_connection_exception_translator"
8
9
 
9
10
  module ActiveRecord
10
- module ConnectionAdapters
11
- class TrilogyAdapter < ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
12
- module DatabaseStatements
13
- READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
14
- :desc, :describe, :set, :show, :use
15
- ) # :nodoc:
16
- private_constant :READ_QUERY
17
-
18
- HIGH_PRECISION_CURRENT_TIMESTAMP = Arel.sql("CURRENT_TIMESTAMP(6)").freeze # :nodoc:
19
- private_constant :HIGH_PRECISION_CURRENT_TIMESTAMP
11
+ # ActiveRecord <= 6.1 support
12
+ if ActiveRecord.version < ::Gem::Version.new('7.0.a')
13
+ class DatabaseConnectionError < ConnectionNotEstablished
14
+ def initialize(message = nil)
15
+ super(message || "Database connection error")
16
+ end
20
17
 
21
- def write_query?(sql) # :nodoc:
22
- !READ_QUERY.match?(sql)
23
- rescue ArgumentError # Invalid encoding
24
- !READ_QUERY.match?(sql.b)
18
+ class << self
19
+ def hostname_error(hostname)
20
+ DatabaseConnectionError.new(<<~MSG)
21
+ There is an issue connecting with your hostname: #{hostname}.\n
22
+ Please check your database configuration and ensure there is a valid connection to your database.
23
+ MSG
25
24
  end
26
25
 
27
- def explain(arel, binds = [])
28
- sql = "EXPLAIN #{to_sql(arel, binds)}"
29
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
30
- result = exec_query(sql, "EXPLAIN", binds)
31
- elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
32
-
33
- MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
26
+ def username_error(username)
27
+ DatabaseConnectionError.new(<<~MSG)
28
+ There is an issue connecting to your database with your username/password, username: #{username}.\n
29
+ Please check your database configuration to ensure the username/password are valid.
30
+ MSG
34
31
  end
32
+ end
33
+ end
35
34
 
36
- def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
37
- result = execute(sql, name, async: async)
38
- ActiveRecord::Result.new(result.fields, result.to_a)
39
- end
35
+ NoDatabaseError.class_exec do
36
+ def self.db_error(db_name)
37
+ NoDatabaseError.new(<<~MSG)
38
+ We could not find your database: #{db_name}. Available database configurations can be found in config/database.yml file.
40
39
 
41
- alias exec_without_stmt exec_query
40
+ To resolve this error:
42
41
 
43
- def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
44
- execute(to_sql(sql, binds), name)
45
- end
42
+ - Did you create the database for this app, or delete it? You may need to create your database.
43
+ - Has the database name changed? Check your database.yml config has the correct database name.
46
44
 
47
- def exec_delete(sql, name = nil, binds = [])
48
- result = execute(to_sql(sql, binds), name)
49
- result.affected_rows
50
- end
51
-
52
- alias :exec_update :exec_delete
53
-
54
- def high_precision_current_timestamp
55
- HIGH_PRECISION_CURRENT_TIMESTAMP
56
- end
45
+ To create your database, run:\n\n bin/rails db:create
46
+ MSG
47
+ end
48
+ end
49
+ end
57
50
 
58
- private
59
- def last_inserted_id(result)
60
- result.last_insert_id
61
- end
51
+ if ActiveRecord.version < ::Gem::Version.new('6.1.a') # ActiveRecord <= 6.0 support
52
+ require "active_record/database_configurations"
53
+ DatabaseConfigurations.class_exec do
54
+ def resolve(config) # :nodoc:
55
+ @resolver ||= ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(::ActiveRecord::Base.configurations)
56
+ @resolver.resolve(config)
62
57
  end
58
+ end
59
+ end
63
60
 
61
+ module ConnectionAdapters
62
+ class TrilogyAdapter < ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
64
63
  ER_BAD_DB_ERROR = 1049
65
64
  ER_ACCESS_DENIED_ERROR = 1045
66
65
 
67
66
  ADAPTER_NAME = "Trilogy"
68
67
 
69
- include DatabaseStatements
68
+ include Trilogy::DatabaseStatements
70
69
 
71
70
  SSL_MODES = {
72
- SSL_MODE_DISABLED: Trilogy::SSL_DISABLED,
73
- SSL_MODE_PREFERRED: Trilogy::SSL_PREFERRED_NOVERIFY,
74
- SSL_MODE_REQUIRED: Trilogy::SSL_REQUIRED_NOVERIFY,
75
- SSL_MODE_VERIFY_CA: Trilogy::SSL_VERIFY_CA,
76
- SSL_MODE_VERIFY_IDENTITY: Trilogy::SSL_VERIFY_IDENTITY
71
+ SSL_MODE_DISABLED: ::Trilogy::SSL_DISABLED,
72
+ SSL_MODE_PREFERRED: ::Trilogy::SSL_PREFERRED_NOVERIFY,
73
+ SSL_MODE_REQUIRED: ::Trilogy::SSL_REQUIRED_NOVERIFY,
74
+ SSL_MODE_VERIFY_CA: ::Trilogy::SSL_VERIFY_CA,
75
+ SSL_MODE_VERIFY_IDENTITY: ::Trilogy::SSL_VERIFY_IDENTITY
77
76
  }.freeze
78
77
 
79
78
  class << self
80
79
  def new_client(config)
81
80
  config[:ssl_mode] = parse_ssl_mode(config[:ssl_mode]) if config[:ssl_mode]
82
81
  ::Trilogy.new(config)
83
- rescue Trilogy::ConnectionError, Trilogy::ProtocolError => error
82
+ rescue ::Trilogy::ConnectionError, ::Trilogy::ProtocolError => error
84
83
  raise translate_connect_error(config, error)
85
84
  end
86
85
 
@@ -88,7 +87,6 @@ module ActiveRecord
88
87
  return mode if mode.is_a? Integer
89
88
 
90
89
  m = mode.to_s.upcase
91
- # enable Mysql2 client compatibility
92
90
  m = "SSL_MODE_#{m}" unless m.start_with? "SSL_MODE_"
93
91
 
94
92
  SSL_MODES.fetch(m.to_sym, mode)
@@ -101,13 +99,26 @@ module ActiveRecord
101
99
  when ER_ACCESS_DENIED_ERROR
102
100
  ActiveRecord::DatabaseConnectionError.username_error(config[:username])
103
101
  else
104
- if error.message.match?(/TRILOGY_DNS_ERROR/)
102
+ if error.message.include?("TRILOGY_DNS_ERROR")
105
103
  ActiveRecord::DatabaseConnectionError.hostname_error(config[:host])
106
104
  else
107
105
  ActiveRecord::ConnectionNotEstablished.new(error.message)
108
106
  end
109
107
  end
110
108
  end
109
+
110
+ private
111
+ def initialize_type_map(m)
112
+ super if ActiveRecord.version >= ::Gem::Version.new('7.0.a')
113
+
114
+ m.register_type(%r(char)i) do |sql_type|
115
+ limit = extract_limit(sql_type)
116
+ Type.lookup(:string, adapter: :trilogy, limit: limit)
117
+ end
118
+
119
+ m.register_type %r(^enum)i, Type.lookup(:string, adapter: :trilogy)
120
+ m.register_type %r(^set)i, Type.lookup(:string, adapter: :trilogy)
121
+ end
111
122
  end
112
123
 
113
124
  def initialize(connection, logger, connection_options, config)
@@ -118,6 +129,8 @@ module ActiveRecord
118
129
  )
119
130
  end
120
131
 
132
+ TYPE_MAP = Type::TypeMap.new.tap { |m| initialize_type_map(m) }
133
+
121
134
  def supports_json?
122
135
  !mariadb? && database_version >= "5.7.8"
123
136
  end
@@ -157,8 +170,6 @@ module ActiveRecord
157
170
  @lock.synchronize do
158
171
  disconnect!
159
172
  connect
160
- rescue StandardError => original_exception
161
- raise translate_exception_class(original_exception, nil, nil)
162
173
  end
163
174
  end
164
175
 
@@ -170,21 +181,11 @@ module ActiveRecord
170
181
  end
171
182
  end
172
183
 
173
- def raw_execute(sql, name, async: false, allow_retry: false, uses_transaction: true)
174
- mark_transaction_written_if_write(sql)
175
-
176
- log(sql, name, async: async) do
177
- with_trilogy_connection(allow_retry: allow_retry, uses_transaction: uses_transaction) do |conn|
178
- sync_timezone_changes(conn)
179
- conn.query(sql)
180
- end
181
- end
182
- end
183
-
184
- def execute(sql, name = nil, **kwargs)
184
+ def execute(sql, name = nil, allow_retry: false, **kwargs)
185
185
  sql = transform_query(sql)
186
186
  check_if_write_query(sql)
187
- super
187
+
188
+ raw_execute(sql, name, allow_retry: allow_retry, **kwargs)
188
189
  end
189
190
 
190
191
  def active?
@@ -206,31 +207,39 @@ module ActiveRecord
206
207
  end
207
208
 
208
209
  def discard!
209
- self.connection = nil
210
+ super
211
+ unless connection.nil?
212
+ connection.discard!
213
+ self.connection = nil
214
+ end
210
215
  end
211
216
 
212
- def each_hash(result)
213
- return to_enum(:each_hash, result) unless block_given?
217
+ private
218
+ def text_type?(type)
219
+ TYPE_MAP.lookup(type).is_a?(Type::String) || TYPE_MAP.lookup(type).is_a?(Type::Text)
220
+ end
221
+
222
+ def each_hash(result)
223
+ return to_enum(:each_hash, result) unless block_given?
214
224
 
215
- keys = result.fields.map(&:to_sym)
216
- result.rows.each do |row|
217
- hash = {}
218
- idx = 0
219
- row.each do |value|
220
- hash[keys[idx]] = value
221
- idx += 1
225
+ keys = result.fields.map(&:to_sym)
226
+ result.rows.each do |row|
227
+ hash = {}
228
+ idx = 0
229
+ row.each do |value|
230
+ hash[keys[idx]] = value
231
+ idx += 1
232
+ end
233
+ yield hash
222
234
  end
223
- yield hash
224
- end
225
235
 
226
- nil
227
- end
236
+ nil
237
+ end
228
238
 
229
- def error_number(exception)
230
- exception.error_code if exception.respond_to?(:error_code)
231
- end
239
+ def error_number(exception)
240
+ exception.error_code if exception.respond_to?(:error_code)
241
+ end
232
242
 
233
- private
234
243
  attr_accessor :connection
235
244
 
236
245
  def connect
@@ -243,17 +252,8 @@ module ActiveRecord
243
252
  connect
244
253
  end
245
254
 
246
- def sync_timezone_changes(conn)
247
- # Sync any changes since connection last established.
248
- if ActiveRecord.default_timezone == :local
249
- conn.query_flags |= ::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
250
- else
251
- conn.query_flags &= ~::Trilogy::QUERY_FLAGS_LOCAL_TIMEZONE
252
- end
253
- end
254
-
255
255
  def execute_batch(statements, name = nil)
256
- statements = statements.map { |sql| transform_query(sql) }
256
+ statements = statements.map { |sql| transform_query(sql) } if respond_to?(:transform_query)
257
257
  combine_multi_statements(statements).each do |statement|
258
258
  with_trilogy_connection do |conn|
259
259
  raw_execute(statement, name)
@@ -272,11 +272,11 @@ module ActiveRecord
272
272
  end
273
273
 
274
274
  with_trilogy_connection do |conn|
275
- conn.set_server_option(Trilogy::SET_SERVER_MULTI_STATEMENTS_ON)
275
+ conn.set_server_option(::Trilogy::SET_SERVER_MULTI_STATEMENTS_ON)
276
276
 
277
277
  yield
278
278
  ensure
279
- conn.set_server_option(Trilogy::SET_SERVER_MULTI_STATEMENTS_OFF)
279
+ conn.set_server_option(::Trilogy::SET_SERVER_MULTI_STATEMENTS_OFF)
280
280
  end
281
281
  end
282
282
 
@@ -317,7 +317,20 @@ module ActiveRecord
317
317
  end
318
318
  end
319
319
 
320
+ if ActiveRecord.version < ::Gem::Version.new('7.0.a') # For ActiveRecord <= 6.1
321
+ def default_timezone
322
+ ActiveRecord::Base.default_timezone
323
+ end
324
+ else # For ActiveRecord 7.0
325
+ def default_timezone
326
+ ActiveRecord.default_timezone
327
+ end
328
+ end
329
+
320
330
  def translate_exception(exception, message:, sql:, binds:)
331
+ if exception.is_a?(::Trilogy::TimeoutError) && !exception.error_code
332
+ return ActiveRecord::AdapterTimeout.new(message, sql: sql, binds: binds)
333
+ end
321
334
  error_code = exception.error_code if exception.respond_to?(:error_code)
322
335
 
323
336
  ::TrilogyAdapter::LostConnectionExceptionTranslator.
@@ -327,6 +340,61 @@ module ActiveRecord
327
340
  def default_prepared_statements
328
341
  false
329
342
  end
343
+
344
+ if ActiveRecord.version < ::Gem::Version.new('6.1.a') # For ActiveRecord <= 6.0
345
+ def prepared_statements?
346
+ @prepared_statements && !prepared_statements_disabled_cache.include?(object_id)
347
+ end
348
+ end
349
+
350
+ ActiveRecord::Type.register(:immutable_string, adapter: :trilogy) do |_, **args|
351
+ Type::ImmutableString.new(true: "1", false: "0", **args)
352
+ end
353
+
354
+ ActiveRecord::Type.register(:string, adapter: :trilogy) do |_, **args|
355
+ Type::String.new(true: "1", false: "0", **args)
356
+ end
357
+
358
+ ActiveRecord::Type.register(:unsigned_integer, Type::UnsignedInteger, adapter: :trilogy)
330
359
  end
360
+
361
+ if ActiveRecord.version < ::Gem::Version.new('6.1.a') # For ActiveRecord <= 6.0
362
+ class PoolConfig < ConnectionSpecification
363
+ def initialize(connection_class, db_config, *args)
364
+ super("primary", db_config, "#{db_config[:adapter]}_connection")
365
+ end
366
+ end
367
+
368
+ SchemaCache.class_exec do
369
+ def self.load_from(filename)
370
+ return unless File.file?(filename)
371
+
372
+ read(filename) do |file|
373
+ if filename.include?(".dump")
374
+ Marshal.load(file)
375
+ else
376
+ if YAML.respond_to?(:unsafe_load)
377
+ YAML.unsafe_load(file)
378
+ else
379
+ YAML.load(file)
380
+ end
381
+ end
382
+ end
383
+ end
384
+
385
+ def self.read(filename, &block)
386
+ if File.extname(filename) == ".gz"
387
+ Zlib::GzipReader.open(filename) { |gz|
388
+ yield gz.read
389
+ }
390
+ else
391
+ yield File.read(filename)
392
+ end
393
+ end
394
+ private_class_method :read
395
+ end
396
+ end
397
+
398
+ ActiveSupport.run_load_hooks(:active_record_trilogyadapter, TrilogyAdapter)
331
399
  end
332
400
  end
@@ -1,5 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ if ActiveRecord.version < ::Gem::Version.new('6.1.a') # ActiveRecord <= 6.0 support
4
+ module ::ActiveRecord
5
+ class QueryAborted < ::ActiveRecord::StatementInvalid
6
+ end
7
+ class AdapterTimeout < ::ActiveRecord::QueryAborted
8
+ end
9
+ end
10
+ end
11
+
3
12
  module TrilogyAdapter
4
13
  module Errors
5
14
  # ServerShutdown will be raised when the database server was shutdown.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrilogyAdapter
4
- VERSION = "3.0.0"
4
+ VERSION = "3.1.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: 3.0.0
4
+ version: 3.1.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: 2023-06-16 00:00:00.000000000 Z
11
+ date: 2023-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trilogy
@@ -30,20 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '7.0'
33
+ version: 6.0.a
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 7.1a
36
+ version: 7.1.a
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: '7.0'
43
+ version: 6.0.a
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 7.1a
46
+ version: 7.1.a
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,7 @@ extra_rdoc_files:
111
111
  files:
112
112
  - LICENSE.md
113
113
  - README.md
114
+ - lib/active_record/connection_adapters/trilogy/database_statements.rb
114
115
  - lib/active_record/connection_adapters/trilogy_adapter.rb
115
116
  - lib/active_record/tasks/trilogy_database_tasks.rb
116
117
  - lib/activerecord-trilogy-adapter.rb