Module: ActiveRecord::ConnectionAdapters::Trilogy::DatabaseStatements
- Included in:
- ActiveRecord::ConnectionAdapters::TrilogyAdapter
- Defined in:
- lib/active_record/connection_adapters/trilogy/database_statements.rb
Instance Method Summary collapse
- #build_explain_clause(options = []) ⇒ Object
-
#exec_delete(sql, name = nil, binds = []) ⇒ Object
(also: #exec_update)
:nodoc:.
-
#exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) ⇒ Object
:nodoc:.
- #exec_query(sql, name = "SQL", binds = [], prepare: false, **kwargs) ⇒ Object
- #execute(sql, name = nil, **kwargs) ⇒ Object
- #explain(arel, binds = [], options = []) ⇒ Object
- #high_precision_current_timestamp ⇒ Object
-
#internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) ⇒ Object
:nodoc:.
-
#select_all ⇒ Object
:nodoc:.
-
#write_query?(sql) ⇒ Boolean
:nodoc:.
Instance Method Details
#build_explain_clause(options = []) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 98 def build_explain_clause( = []) return "EXPLAIN" if .empty? explain_clause = "EXPLAIN #{.join(" ").upcase}" if analyze_without_explain? && explain_clause.include?("ANALYZE") explain_clause.sub("EXPLAIN ", "") else explain_clause end end |
#exec_delete(sql, name = nil, binds = []) ⇒ Object Also known as: exec_update
:nodoc:
83 84 85 86 87 88 89 90 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 83 def exec_delete(sql, name = nil, binds = []) # :nodoc: sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) result = raw_execute(to_sql(sql, binds), name) result.affected_rows end |
#exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) ⇒ Object
:nodoc:
75 76 77 78 79 80 81 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 75 def exec_insert(sql, name, binds, pk = nil, sequence_name = nil, returning: nil) # :nodoc: sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) raw_execute(to_sql(sql, binds), name) end |
#exec_query(sql, name = "SQL", binds = [], prepare: false, **kwargs) ⇒ Object
62 63 64 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 62 def exec_query(sql, name = "SQL", binds = [], prepare: false, **kwargs) internal_exec_query(sql, name, binds, prepare: prepare, **kwargs) end |
#execute(sql, name = nil, **kwargs) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 15 def execute(sql, name = nil, **kwargs) sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) result = raw_execute(sql, name, **kwargs) ActiveRecord::Result.new(result.fields, result.to_a) end |
#explain(arel, binds = [], options = []) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 30 def explain(arel, binds = []) sql = "EXPLAIN #{to_sql(arel, binds)}" start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = internal_exec_query(sql, "EXPLAIN", binds) elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) end |
#high_precision_current_timestamp ⇒ Object
94 95 96 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 94 def HIGH_PRECISION_CURRENT_TIMESTAMP end |
#internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) ⇒ Object
:nodoc:
66 67 68 69 70 71 72 73 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 66 def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) # :nodoc: sql = transform_query(sql) check_if_write_query(sql) mark_transaction_written_if_write(sql) result = raw_execute(sql, name, async: async) ActiveRecord::Result.new(result.fields, result.to_a) end |
#select_all ⇒ Object
:nodoc:
39 40 41 42 43 44 45 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 39 def select_all(*, **) # :nodoc: result = super with_trilogy_connection do |conn| conn.next_result while conn.more_results_exist? end result end |
#write_query?(sql) ⇒ Boolean
:nodoc:
24 25 26 27 28 |
# File 'lib/active_record/connection_adapters/trilogy/database_statements.rb', line 24 def write_query?(sql) # :nodoc: !READ_QUERY.match?(sql) rescue ArgumentError # Invalid encoding !READ_QUERY.match?(sql.b) end |