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



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

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