Class: Api::V2::RawController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Api::V2::RawController
- Defined in:
- app/controllers/api/v2/raw_controller.rb
Overview
require ‘model_driven_api/version’
Instance Method Summary collapse
-
#sql ⇒ Object
api :GET, ‘/api/v2/raw/sql’.
Instance Method Details
#sql ⇒ Object
api :GET, ‘/api/v2/raw/sql’
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/api/v2/raw_controller.rb', line 8 def sql # if params is nil, render 400 render json: { error: "Query is required" }, status: 400 and return if params[:query].nil? query = params[:query] first_element = SafeSqlExecutor.execute_select(query).first rescue nil # Error if first_element does not contain a key called results render json: { error: "Query must return a key called result" }, status: 400 and return if first_element.nil? || !first_element.key?("result") render json: first_element["result"], status: 200 end |