Module: Sequent::Core::Helpers::PgsqlHelpers

Included in:
EventStore, SnapshotStore
Defined in:
lib/sequent/core/helpers/pgsql_helpers.rb

Instance Method Summary collapse

Instance Method Details

#call_procedure(connection, procedure, params) ⇒ Object



7
8
9
10
11
12
# File 'lib/sequent/core/helpers/pgsql_helpers.rb', line 7

def call_procedure(connection, procedure, params)
  fail ArgumentError if procedure.blank?

  statement = "CALL #{quote_ident(procedure)}(#{bind_placeholders(params)})"
  connection.exec_update(statement, procedure, params)
end

#query_function(connection, function, params, columns: []) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sequent/core/helpers/pgsql_helpers.rb', line 14

def query_function(connection, function, params, columns: [])
  fail ArgumentError if function.blank?

  cols = columns.blank? ? '*' : columns.map { |c| PG::Connection.quote_ident(c) }.join(', ')
  query = "SELECT #{cols} FROM #{quote_ident(function)}(#{bind_placeholders(params)})"
  connection.exec_query(query, function, params)
end