class FluentQuery::Drivers::Shared::Tokens::SQLToken
PostgreSQL query native token.
Constants
- TRANSFORMER
Holds token transformer.
Public Class Methods
new(driver, query, subtokens)
click to toggle source
Initializes token.
# File lib/fluent-query/drivers/shared/tokens/sql.rb, line 44 def initialize(driver, query, subtokens) @_query = query @_driver = driver @_subtokens = subtokens end
Public Instance Methods
render!(mode = :build)
click to toggle source
Renders this token.
Name of the token transforms to the SQL
form. Joins arguments in Array by commas, in Hash by name = value separated by commas form or by token body itself if token is operator.
Mode can be :prepare or :build. Preparing means building the query without expanding the formatting directives.
# File lib/fluent-query/drivers/shared/tokens/sql.rb, line 62 def render!(mode = :build) result = "" processor = @_query.processor # Transforms all subtokens to real string SQL tokens @_subtokens.each do |token| arguments = token.arguments name = token.name transformed = self._transform_token(name.to_s) operator = @_driver.operator_token? name if operator glue = transformed else glue = "," end first = arguments.first if first.array? arguments_result = processor.process_array(first, glue) elsif first.hash? arguments_result = processor.process_hash(first, glue) elsif first.symbol? arguments_result = processor.process_identifiers(arguments) else arguments_result = processor.process_formatted(arguments, mode) end result << transformed << " " << arguments_result << " " end return result end
Protected Instance Methods
_transform_token(token_name)
click to toggle source
Transform token name to the SQL
token.
Upper case characters handles as separators, so for example:
'leftJoin' will be transformed to 'LEFT JOIN'
# File lib/fluent-query/drivers/shared/tokens/sql.rb, line 108 def _transform_token(token_name) sql_name = token_name.to_s.gsub(self.class::TRANSFORMER, ' \1') sql_name.upcase! return sql_name end
unknown_token()
click to toggle source
Returns appropriate class for anonymous tokens.
# File lib/fluent-query/drivers/shared/tokens/sql.rb, line 119 def unknown_token FluentQuery::Drivers::Shared::Tokens::SQLToken end