Module: QuoteSql::Formater

Included in:
QuoteSql
Defined in:
lib/quote_sql/formater.rb

Constant Summary collapse

PG_FORMAT_BIN =
`which pg_format`.chomp.presence

Instance Method Summary collapse

Instance Method Details

#dsqlObject



6
7
8
9
# File 'lib/quote_sql/formater.rb', line 6

def dsql
  puts to_formatted_sql
  nil
end

#to_formatted_sqlObject Also known as: to_sqf



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quote_sql/formater.rb', line 11

def to_formatted_sql
  sql = respond_to?(:to_sql) ? to_sql : to_s
  Niceql::Prettifier.prettify_sql(sql.gsub(/(?<=[^%])%(?=\S)/, "%%"))

  # IO.popen(PG_FORMAT_BIN, "r+", err: "/dev/null") do |f|
  #   f.write(sql)
  #   f.close_write
  #   f.read
  # end

end