Method: PgQuery.deparse

Defined in:
lib/pg_query/deparse.rb

.deparse(tree) ⇒ Object

Reconstruct all of the parsed queries into their original form



9
10
11
12
13
14
15
16
17
# File 'lib/pg_query/deparse.rb', line 9

def self.deparse(tree)
  if PgQuery::ParseResult.method(:encode).arity == 1
    PgQuery.deparse_protobuf(PgQuery::ParseResult.encode(tree)).force_encoding('UTF-8')
  elsif PgQuery::ParseResult.method(:encode).arity == -1
    PgQuery.deparse_protobuf(PgQuery::ParseResult.encode(tree, recursion_limit: 1_000)).force_encoding('UTF-8')
  else
    raise ArgumentError, 'Unsupported protobuf Ruby API'
  end
end