|
5 | 5 | gem "trilogy", "~> 2.4"
|
6 | 6 | require "trilogy"
|
7 | 7 |
|
| 8 | +require "active_record/connection_adapters/trilogy/database_statements" |
8 | 9 | require "active_record/connection_adapters/trilogy/lost_connection_exception_translator"
|
9 | 10 | require "active_record/connection_adapters/trilogy/errors"
|
10 | 11 |
|
@@ -37,95 +38,13 @@ def trilogy_connection(config)
|
37 | 38 | end
|
38 | 39 | module ConnectionAdapters
|
39 | 40 | class TrilogyAdapter < AbstractMysqlAdapter
|
40 |
| - module DatabaseStatements |
41 |
| - READ_QUERY = AbstractAdapter.build_read_query_regexp( |
42 |
| - :desc, :describe, :set, :show, :use |
43 |
| - ) # :nodoc: |
44 |
| - private_constant :READ_QUERY |
45 |
| - |
46 |
| - HIGH_PRECISION_CURRENT_TIMESTAMP = Arel.sql("CURRENT_TIMESTAMP(6)").freeze # :nodoc: |
47 |
| - private_constant :HIGH_PRECISION_CURRENT_TIMESTAMP |
48 |
| - |
49 |
| - def select_all(*, **) # :nodoc: |
50 |
| - result = nil |
51 |
| - with_raw_connection do |conn| |
52 |
| - result = super |
53 |
| - conn.next_result while conn.more_results_exist? |
54 |
| - end |
55 |
| - result |
56 |
| - end |
57 |
| - |
58 |
| - def write_query?(sql) # :nodoc: |
59 |
| - !READ_QUERY.match?(sql) |
60 |
| - rescue ArgumentError # Invalid encoding |
61 |
| - !READ_QUERY.match?(sql.b) |
62 |
| - end |
63 |
| - |
64 |
| - def explain(arel, binds = [], options = []) |
65 |
| - sql = build_explain_clause(options) + " " + to_sql(arel, binds) |
66 |
| - start = Process.clock_gettime(Process::CLOCK_MONOTONIC) |
67 |
| - result = exec_query(sql, "EXPLAIN", binds) |
68 |
| - elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start |
69 |
| - |
70 |
| - MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) |
71 |
| - end |
72 |
| - |
73 |
| - def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) |
74 |
| - sql = transform_query(sql) |
75 |
| - check_if_write_query(sql) |
76 |
| - |
77 |
| - result = raw_execute(sql, name, async: async) |
78 |
| - ActiveRecord::Result.new(result.fields, result.to_a) |
79 |
| - end |
80 |
| - |
81 |
| - alias exec_without_stmt exec_query |
82 |
| - |
83 |
| - def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) |
84 |
| - sql = transform_query(sql) |
85 |
| - check_if_write_query(sql) |
86 |
| - |
87 |
| - raw_execute(to_sql(sql, binds), name) |
88 |
| - end |
89 |
| - |
90 |
| - def exec_delete(sql, name = nil, binds = []) |
91 |
| - sql = transform_query(sql) |
92 |
| - check_if_write_query(sql) |
93 |
| - |
94 |
| - result = raw_execute(to_sql(sql, binds), name) |
95 |
| - result.affected_rows |
96 |
| - end |
97 |
| - |
98 |
| - alias :exec_update :exec_delete |
99 |
| - |
100 |
| - def high_precision_current_timestamp |
101 |
| - HIGH_PRECISION_CURRENT_TIMESTAMP |
102 |
| - end |
103 |
| - |
104 |
| - def build_explain_clause(options = []) |
105 |
| - return "EXPLAIN" if options.empty? |
106 |
| - |
107 |
| - explain_clause = "EXPLAIN #{options.join(" ").upcase}" |
108 |
| - |
109 |
| - if analyze_without_explain? && explain_clause.include?("ANALYZE") |
110 |
| - explain_clause.sub("EXPLAIN ", "") |
111 |
| - else |
112 |
| - explain_clause |
113 |
| - end |
114 |
| - end |
115 |
| - |
116 |
| - private |
117 |
| - def last_inserted_id(result) |
118 |
| - result.last_insert_id |
119 |
| - end |
120 |
| - end |
121 |
| - |
122 | 41 | ER_BAD_DB_ERROR = 1049
|
123 | 42 | ER_DBACCESS_DENIED_ERROR = 1044
|
124 | 43 | ER_ACCESS_DENIED_ERROR = 1045
|
125 | 44 |
|
126 | 45 | ADAPTER_NAME = "Trilogy"
|
127 | 46 |
|
128 |
| - include DatabaseStatements |
| 47 | + include Trilogy::DatabaseStatements |
129 | 48 |
|
130 | 49 | SSL_MODES = {
|
131 | 50 | SSL_MODE_DISABLED: ::Trilogy::SSL_DISABLED,
|
|
0 commit comments