module PGTrunk::Operation::SQLHelpers

@private Add helpers for building SQL queries

Public Instance Methods

each(&block) click to toggle source

Iterate by sorted operation definitions extracted from the database

# File lib/pg_trunk/core/operation/sql_helpers.rb, line 23
def each(&block)
  return to_enum unless block_given?

  fetch
    .map { |item| new(**item.symbolize_keys) }
    .sort
    .each { |op| block.call(op) }
end
fetch() click to toggle source
# File lib/pg_trunk/core/operation/sql_helpers.rb, line 34
def fetch
  query = from_sql&.call(PGTrunk.database.server_version)
  query.blank? ? [] : PGTrunk.database.execute(query)
end
from_sql(&block) click to toggle source

Get/set the block to extract operation definitions from the database. @yield [Proc] the block returning sql @yieldparam [#to_s] version The current version of the database

# File lib/pg_trunk/core/operation/sql_helpers.rb, line 16
def from_sql(&block)
  @from_sql = block if block
  @from_sql ||= nil
end
quote(str) click to toggle source
# File lib/pg_trunk/core/operation/sql_helpers.rb, line 40
def quote(str)
  PGTrunk.database.quote(str)
end