Class: Babik::QuerySet::SQLRenderer
- Inherits:
-
Object
- Object
- Babik::QuerySet::SQLRenderer
- Defined in:
- lib/babik/queryset/components/sql_renderer.rb
Overview
SQL renderer
Constant Summary collapse
- TEMPLATE_PATH =
Where the SQL templates are
"#{__dir__}/../templates"
Instance Attribute Summary collapse
-
#queryset ⇒ Object
readonly
Returns the value of attribute queryset.
Instance Method Summary collapse
-
#delete ⇒ String
Render the DELETE statement.
-
#initialize(queryset) ⇒ SQLRenderer
constructor
Construct a new SQL rendered for a QuerySet.
-
#left_joins ⇒ String
Return the SQL representation of all joins of the QuerySet.
-
#select ⇒ String
Render the SELECT statement.
-
#update(update_command) ⇒ String
Render the UPDATE statement.
Constructor Details
#initialize(queryset) ⇒ SQLRenderer
Construct a new SQL rendered for a QuerySet
18 19 20 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 18 def initialize(queryset) @queryset = queryset end |
Instance Attribute Details
#queryset ⇒ Object (readonly)
Returns the value of attribute queryset.
11 12 13 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 11 def queryset @queryset end |
Instance Method Details
#delete ⇒ String
Render the DELETE statement
40 41 42 43 44 45 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 40 def delete @queryset.project(['id']) sql = _render('delete/main.sql.erb') @queryset.unproject sql end |
#left_joins ⇒ String
Return the SQL representation of all joins of the QuerySet
49 50 51 52 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 49 def left_joins # Join all left joins and return a string with the SQL code @queryset.left_joins_by_alias.values.map(&:sql).join("\n") end |
#select ⇒ String
Render the SELECT statement
24 25 26 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 24 def select _render('select/main.sql.erb') end |
#update(update_command) ⇒ String
Render the UPDATE statement
31 32 33 34 35 36 |
# File 'lib/babik/queryset/components/sql_renderer.rb', line 31 def update(update_command) @queryset.project!(['id']) sql = _render('update/main.sql.erb', {update_command: update_command}) @queryset.unproject! sql end |