Class: Nquery::QueriesController
Constant Summary
AuthorizesCollection::COLLECTION_REQUIREMENTS
Instance Method Summary
collapse
#breadcrumbs, #set_breadcrumbs
Instance Method Details
#create ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/nquery/queries_controller.rb', line 17
def create
@query = Query.new(query_params.merge(creator: current_nquery_user))
if @query.save
redirect_to edit_query_path(@query), notice: "Query created."
else
@data_sources = DataSource.active.order(:name)
@schema_tables = schema_tables
render :new, status: :unprocessable_content
end
end
|
#edit ⇒ Object
28
29
30
31
|
# File 'app/controllers/nquery/queries_controller.rb', line 28
def edit
@data_sources = DataSource.active.order(:name)
@schema_tables = schema_tables
end
|
#new ⇒ Object
11
12
13
14
15
|
# File 'app/controllers/nquery/queries_controller.rb', line 11
def new
@query = Query.new(statement: "SELECT 1 AS example")
@data_sources = DataSource.active.order(:name)
@schema_tables = schema_tables
end
|
#run ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/controllers/nquery/queries_controller.rb', line 55
def run
result = QueryRunner.new(
data_source: @data_source,
statement: params[:statement],
user: current_nquery_user
).run
render json: result
rescue QueryRunner::PermissionError => e
render json: { error: e.message }, status: :forbidden
rescue QueryRunner::Error => e
render json: { error: e.message }, status: :unprocessable_content
end
|
#schema ⇒ Object
69
70
71
|
# File 'app/controllers/nquery/queries_controller.rb', line 69
def schema
render json: { tables: Nquery::SchemaExplorer.tables_for(@data_source) }
end
|
#show ⇒ Object
52
53
|
# File 'app/controllers/nquery/queries_controller.rb', line 52
def show
end
|
#update ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'app/controllers/nquery/queries_controller.rb', line 33
def update
if @query.update(query_params)
respond_to do |format|
format.html { redirect_to edit_query_path(@query), notice: "Query saved." }
format.json { render json: { ok: true, notice: "Query saved." } }
end
else
@data_sources = DataSource.active.order(:name)
@schema_tables = schema_tables
respond_to do |format|
format.html { render :edit, status: :unprocessable_content }
format.json {
render json: { error: @query.errors.full_messages.to_sentence.presence || "Query could not be saved." },
status: :unprocessable_content
}
end
end
end
|