Module: ActiveRecord::ConnectionAdapters::Trino::DatabaseStatements

Included in:
ActiveRecord::ConnectionAdapters::TrinoAdapter
Defined in:
lib/active_record/connection_adapters/trino/database_statements.rb

Defined Under Namespace

Classes: InternalResult

Constant Summary collapse

SLOW_QUERY_NOTIFICATION =
"active_record_trino.slow_query"
STAT_FIELDS =
%i[
  state
  queued_time_millis
  elapsed_time_millis
  cpu_time_millis
  wall_time_millis
].freeze

Instance Method Summary collapse

Instance Method Details

#exec_query(sql, name = "SQL", binds = [], prepare: false, async: false) ⇒ Object

Rails 7.1 public path.



24
25
26
# File 'lib/active_record/connection_adapters/trino/database_statements.rb', line 24

def exec_query(sql, name = "SQL", binds = [], prepare: false, async: false)
  internal_exec_query(sql, name, binds, prepare: prepare, async: async)
end

#execute(sql, name = nil, **_kwargs) ⇒ Object



19
20
21
# File 'lib/active_record/connection_adapters/trino/database_statements.rb', line 19

def execute(sql, name = nil, **_kwargs)
  log(sql, name) { run_trino_query(sql) }
end

#internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false) ⇒ Object

Rails 7.2+/8.0 canonical path that AR’s select_all/select route through. rubocop:disable Lint/UnusedMethodArgument, Metrics/ParameterLists



30
31
32
33
34
35
36
37
38
# File 'lib/active_record/connection_adapters/trino/database_statements.rb', line 30

def internal_exec_query(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false)
  unless binds.empty?
    raise ActiveRecord::Trino::Error,
          "activerecord-trino-adapter: bind variables are not supported; got #{binds.size} bind(s)"
  end

  internal = log(sql, name) { run_trino_query(sql) }
  ActiveRecord::Result.new(internal.column_names, internal.rows, internal.column_types)
end

#select_value(arel, name = nil, binds = []) ⇒ Object

rubocop:enable Lint/UnusedMethodArgument, Metrics/ParameterLists



41
42
43
44
# File 'lib/active_record/connection_adapters/trino/database_statements.rb', line 41

def select_value(arel, name = nil, binds = [])
  result = select_all(arel, name, binds)
  result.rows.first&.first
end

#select_values(arel, name = nil, binds = []) ⇒ Object



46
47
48
49
# File 'lib/active_record/connection_adapters/trino/database_statements.rb', line 46

def select_values(arel, name = nil, binds = [])
  result = select_all(arel, name, binds)
  result.rows.map(&:first)
end