Method: NoSE::Query#unparse

Defined in:
lib/nose/statements/query.rb

#unparseString

Produce the SQL text corresponding to this query

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/nose/statements/query.rb', line 43

def unparse
  field_namer = -> (f) { field_path f }

  query = 'SELECT ' + @select.map(&field_namer).join(', ')
  query << " FROM #{from_path @graph.longest_path}"
  query << where_clause(field_namer)

  query << ' ORDER BY ' << @order.map(&field_namer).join(', ') \
    unless @order.empty?
  query << " LIMIT #{@limit}" unless @limit.nil?
  query << " -- #{@comment}" unless @comment.nil?

  query
end