Class: Api::V3::RawController

Inherits:
ApplicationController show all
Defined in:
app/controllers/api/v3/raw_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#create, #destroy, #index, #show, #update

Instance Method Details

#sqlObject



4
5
6
7
8
9
10
11
12
13
# File 'app/controllers/api/v3/raw_controller.rb', line 4

def sql
  return render json: { error: "Query is required" }, status: 400 if params[:query].nil?

  result = SafeSqlExecutor.execute_select(params[:query]).to_a
  render json: result, status: 200
rescue ArgumentError => e
  render json: { error: e.message }, status: 400
rescue ActiveRecord::StatementInvalid => e
  render json: { error: e.message }, status: 400
end