Class: Jaql::SqlGeneration::RunnableQuery

Inherits:
Query
  • Object
show all
Extended by:
RunnableQueryFactoryMethods
Defined in:
lib/jaql/sql_generation/runnable_query.rb

Overview

A RunnableQuery extends Query with the ability to produce JSON from postgres by applying spec to scope

Direct Known Subclasses

ActiveRecordQuery, SequelQuery

Defined Under Namespace

Classes: Context

Constant Summary collapse

JSON_RESULT_COL_NAME =

Run the query and produce JSON

'json_data'.freeze

Constants inherited from Query

Query::ARRAY_RETURN_TYPE, Query::ROW_RETURN_TYPE

Instance Attribute Summary

Attributes inherited from Query

#table_name_alias

Instance Method Summary collapse

Methods included from RunnableQueryFactoryMethods

for

Methods inherited from Query

#fields_sql, #json_array_sql, #json_row_sql, #json_sql, #scope_options

Constructor Details

#initialize(scope, spec, resolver) ⇒ RunnableQuery



12
13
14
15
16
# File 'lib/jaql/sql_generation/runnable_query.rb', line 12

def initialize(scope, spec, resolver)
  @scope = scope

  super(Context.new, spec, resolver)
end

Instance Method Details

#json_arrayObject



21
22
23
# File 'lib/jaql/sql_generation/runnable_query.rb', line 21

def json_array
  run_returning ARRAY_RETURN_TYPE
end

#json_rowObject



25
26
27
# File 'lib/jaql/sql_generation/runnable_query.rb', line 25

def json_row
  run_returning ROW_RETURN_TYPE
end

#run_returning(return_type) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/jaql/sql_generation/runnable_query.rb', line 29

def run_returning(return_type)
  select_sql = scope_selected_sql

  sql_to_run = json_sql(select_sql, JSON_RESULT_COL_NAME, return_type)
  puts "\n\n****************************** sql_to_run:\n#{sql_to_run} \n"
  run(sql_to_run, JSON_RESULT_COL_NAME)
end