Class: SqlQueryExecutor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_query_executor/base.rb

Overview

:nodoc:

Constant Summary collapse

STRING_SPACE =

:nodoc:

"$SS$"
QUERY_SPACE =
"$QS$"
TEMP_SPACE =
"$TS$"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'lib/sql_query_executor/base.rb', line 12

def initialize(query)
  if query.respond_to?(:size) && query.size == 1 && !query.is_a?(Hash)
    @query = query.first
  else
    @query = query
  end

  message = check_query
  raise ArgumentError.new(message) if message
end

Class Method Details

.where(collection, *query) ⇒ Object

Recursive method that divides the query in sub queries, executes each part individually and finally relates its results as specified in the query.



52
53
54
# File 'lib/sql_query_executor/base.rb', line 52

def self.where(collection, *query)
  self.new(query).execute!(collection)
end

Instance Method Details

#execute!(collection) ⇒ Object



23
24
25
26
27
28
# File 'lib/sql_query_executor/base.rb', line 23

def execute!(collection)
  return [] if @query.empty?
  set_collection(collection)

  convert_query.execute!(@collection)
end

#selectorObject



40
41
42
43
44
45
46
47
48
# File 'lib/sql_query_executor/base.rb', line 40

def selector
  return @selector if @selector

  @selector = @query
  
  return @query if @query.is_a?(Hash)

  @selector = convert_query.selector
end

#to_sqlObject



30
31
32
33
34
35
36
37
38
# File 'lib/sql_query_executor/base.rb', line 30

def to_sql
  return @to_sql if @to_sql

  @to_sql = @query
  
  return @query if @query.is_a?(String)

  @to_sql = convert_query.to_sql
end