Class: FluentQuery::Drivers::Shared::Tokens::SQLToken

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent-query/drivers/shared/tokens/sql.rb

Overview

PostgreSQL query native token.

Constant Summary collapse

TRANSFORMER =

Holds token transformer.

/([A-Z])/

Instance Method Summary collapse

Constructor Details

#initialize(driver, query, subtokens) ⇒ SQLToken

Returns a new instance of SQLToken.



44
45
46
47
48
# File 'lib/fluent-query/drivers/shared/tokens/sql.rb', line 44

def initialize(driver, query, subtokens)
    @_query = query
    @_driver = driver
    @_subtokens = subtokens
end

Instance Method Details

#render!(mode = :build) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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