Class: SqlQueryExecutor::Base
- Inherits:
-
Object
- Object
- SqlQueryExecutor::Base
- 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
-
.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.
Instance Method Summary collapse
- #execute!(collection) ⇒ Object
-
#initialize(query) ⇒ Base
constructor
A new instance of Base.
- #selector ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(query) ⇒ Base
Returns a new instance of Base.
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 = check_query raise ArgumentError.new() if 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 |
#selector ⇒ Object
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_sql ⇒ Object
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 |