Class: Prequel::Sql::DerivedQueryColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/prequel/sql/derived_query_column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subquery, name, expression) ⇒ DerivedQueryColumn

Returns a new instance of DerivedQueryColumn.



6
7
8
# File 'lib/prequel/sql/derived_query_column.rb', line 6

def initialize(subquery, name, expression)
  @subquery, @name, @expression = subquery, name, expression
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



4
5
6
# File 'lib/prequel/sql/derived_query_column.rb', line 4

def expression
  @expression
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/prequel/sql/derived_query_column.rb', line 4

def name
  @name
end

#subqueryObject (readonly)

Returns the value of attribute subquery.



4
5
6
# File 'lib/prequel/sql/derived_query_column.rb', line 4

def subquery
  @subquery
end

Instance Method Details

#qualified_nameObject



18
19
20
# File 'lib/prequel/sql/derived_query_column.rb', line 18

def qualified_name
  "#{subquery.name}__#{name}"
end

#to_select_clause_sqlObject



14
15
16
# File 'lib/prequel/sql/derived_query_column.rb', line 14

def to_select_clause_sql
  "#{expression.to_sql} as #{name}"
end

#to_sqlObject



10
11
12
# File 'lib/prequel/sql/derived_query_column.rb', line 10

def to_sql
  "#{subquery.name}.#{name}"
end