Module: RunningCount::Statement

Defined in:
lib/running_count/statement.rb

Class Method Summary collapse

Class Method Details

.prepare_statement(counter_data) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/running_count/statement.rb', line 17

def prepare_statement(counter_data)
  return if ActiveRecord::Base.connection.exec_query("select name from pg_prepared_statements where name = '#{counter_data[:statement]}'").present?

  ActiveRecord::Base.connection.exec_query(counter_data[:statement_sql])
rescue ActiveRecord::StatementInvalid
  Rails.logger.warn "Statement already exists: #{counter_data[:statement]}"
end

.reconcile_item(item, counter_data) ⇒ Object



29
30
31
32
33
34
# File 'lib/running_count/statement.rb', line 29

def reconcile_item(item, counter_data)
  Storage.clear_item(item, counter_data[:running_set_name])

  destination_id = Format.parse(item)
  ActiveRecord::Base.connection.exec_query("EXECUTE #{counter_data[:statement]}(#{destination_id})")
end

.release_statement(counter_data) ⇒ Object



25
26
27
# File 'lib/running_count/statement.rb', line 25

def release_statement(counter_data)
  ActiveRecord::Base.connection.exec_query(counter_data[:release_sql])
end

.statement_sql(table_name, statement, destination_table_name, set_name, relation, opts) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/running_count/statement.rb', line 8

def statement_sql(table_name, statement, destination_table_name, set_name, relation, opts)
  basic_sql(
    statement,
    destination_table_name,
    set_name,
    inner_sql(table_name, relation, opts),
  )
end