Class: ForestLiana::LiveQueryChecker

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/live_query_checker.rb

Constant Summary collapse

QUERY_SELECT =
/\ASELECT\s.*FROM\s.*\z/im

Instance Method Summary collapse

Constructor Details

#initialize(query, context) ⇒ LiveQueryChecker

Returns a new instance of LiveQueryChecker.


5
6
7
8
# File 'app/services/forest_liana/live_query_checker.rb', line 5

def initialize(query, context)
  @query = query.strip
  @context = context
end

Instance Method Details

#validateObject


10
11
12
13
14
15
16
17
18
# File 'app/services/forest_liana/live_query_checker.rb', line 10

def validate
  raise generate_error 'You cannot execute an empty SQL query.' if @query.blank?

  if @query.include?(';') && @query.index(';') < (@query.length - 1)
    raise generate_error 'You cannot chain SQL queries.'
  end

  raise generate_error 'Only SELECT queries are allowed.' if QUERY_SELECT.match(@query).nil?
end