Class: Querylet::Tree::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/querylet/tree.rb

Instance Method Summary collapse

Instance Method Details

#_eval(context) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/querylet/tree.rb', line 143

def _eval(context)
  content = items.map {|item| item._eval(context)}.join()
  if block == 'array'
  <<-HEREDOC.chomp
(SELECT COALESCE(array_to_json(array_agg(row_to_json(array_row))),'[]'::json) FROM (
#{content}
) array_row)
HEREDOC
  elsif block == 'object'
  <<-HEREDOC.chomp
(SELECT COALESCE(row_to_json(object_row),'{}'::json) FROM (
#{content}
) object_row)
HEREDOC
  else
    content
  end
end