Class: Arel::SelectManager
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
TreeManager
|
|
|
Instance Chain:
|
|
| Inherits: |
Arel::TreeManager
|
| Defined in: | activerecord/lib/arel/select_manager.rb |
Constant Summary
-
DISTINCT =
# File 'activerecord/lib/arel/select_manager.rb', line 11Nodes::Distinct.new.freeze
-
FOR_UPDATE =
# File 'activerecord/lib/arel/select_manager.rb', line 10Nodes::SqlLiteral.new("FOR UPDATE").freeze
-
STRING_OR_SYMBOL_CLASS =
# File 'activerecord/lib/arel/select_manager.rb', line 15[Symbol, String].freeze
Class Method Summary
Instance Attribute Summary
- #limit (also: #taken) rw
-
#limit=(limit)
rw
Alias for #take.
- #offset rw
-
#offset=(amount)
rw
Alias for #skip.
- #projections rw
- #projections=(projections) rw
TreeManager - Inherited
Instance Method Summary
- #as(other)
- #comment(*values)
- #constraints
- #distinct(value = true)
- #distinct_on(value)
- #except(other) (also: #minus)
-
#exists
Produces an
Arel::Nodes::Existsnode. - #from(table)
- #froms
- #group(*columns)
- #having(expr)
- #initialize_copy(other)
- #intersect(other)
- #join(relation, klass = Nodes::InnerJoin)
- #join_sources
- #lateral(table_name = nil)
- #lock(locking = FOR_UPDATE)
- #locked
-
#minus(other)
Alias for #except.
- #on(*exprs)
- #optimizer_hints(*hints)
- #order(*expr)
- #orders
- #outer_join(relation)
- #project(*projections)
- #skip(amount) (also: #offset=)
- #source
- #take(limit) (also: #limit=)
-
#taken
Alias for #limit.
- #union(operation, other = nil)
- #where(expr)
- #where_sql(engine = Table.engine)
- #window(name)
- #with(*subqueries)
- #collapse(exprs) private
Crud - Included
TreeManager - Inherited
FactoryMethods - Included
| #cast, #coalesce, #create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, | |
| #lower | Create a LOWER() function. |
Constructor Details
.new(table = nil) ⇒ SelectManager
# File 'activerecord/lib/arel/select_manager.rb', line 17
def initialize(table = nil) super @ast = Nodes::SelectStatement.new(table) @ctx = @ast.cores.last end
Instance Attribute Details
#limit (rw) Also known as: #taken
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 29
def limit @ast.limit && @ast.limit.expr end
#limit=(limit) (rw)
Alias for #take.
# File 'activerecord/lib/arel/select_manager.rb', line 264
alias limit= take
#offset (rw)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 38
def offset @ast.offset && @ast.offset.expr end
#offset=(amount) (rw)
Alias for #skip.
# File 'activerecord/lib/arel/select_manager.rb', line 50
alias :offset= :skip
#projections (rw)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 154
def projections @ctx.projections end
#projections=(projections) (rw)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 158
def projections=(projections) @ctx.projections = projections end
Instance Method Details
#as(other)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 58
def as(other) create_table_alias grouping(@ast), Nodes::SqlLiteral.new(other, retryable: true) end
#collapse(exprs) (private)
[ GitHub ]#comment(*values)
[ GitHub ]#constraints
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 34
def constraints @ctx.wheres end
#distinct(value = true)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 169
def distinct(value = true) if value @ctx.set_quantifier = DISTINCT else @ctx.set_quantifier = nil end self end
#distinct_on(value)
[ GitHub ]#except(other) Also known as: #minus
[ GitHub ]#exists
Produces an Arel::Nodes::Exists node
#from(table)
[ GitHub ]#froms
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 113
def froms @ast.cores.filter_map { |x| x.from } end
#group(*columns)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 84
def group(*columns) columns.each do |column| # FIXME: backwards compat case column when Nodes::SqlLiteral when String column = Nodes::SqlLiteral.new(column) when Symbol column = Nodes::SqlLiteral.new(column.name) end @ctx.groups.push Nodes::Group.new column end self end
#having(expr)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 134
def having(expr) @ctx.havings << expr self end
#initialize_copy(other)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 24
def initialize_copy(other) super @ctx = @ast.cores.last end
#intersect(other)
[ GitHub ]#join(relation, klass = Nodes::InnerJoin)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 117
def join(relation, klass = Nodes::InnerJoin) return self unless relation case relation when String, Nodes::SqlLiteral raise EmptyJoinError if relation.empty? klass = Nodes::StringJoin end @ctx.source.right << create_join(relation, nil, klass) self end
#join_sources
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 266
def join_sources @ctx.source.right end
#lateral(table_name = nil)
[ GitHub ]#lock(locking = FOR_UPDATE)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 62
def lock(locking = FOR_UPDATE) case locking when true locking = FOR_UPDATE when Arel::Nodes::SqlLiteral when String locking = Arel.sql locking end @ast.lock = Nodes::Lock.new(locking) self end
#locked
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 75
def locked @ast.lock end
#minus(other)
Alias for #except.
# File 'activerecord/lib/arel/select_manager.rb', line 234
alias :minus :except
#on(*exprs)
[ GitHub ]#optimizer_hints(*hints)
[ GitHub ]#order(*expr)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 187
def order(*expr) # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically @ast.orders.concat expr.map! { |x| STRING_OR_SYMBOL_CLASS.include?(x.class) ? Nodes::SqlLiteral.new(x.to_s) : x } self end
#orders
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 195
def orders @ast.orders end
#outer_join(relation)
[ GitHub ]#project(*projections)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 145
def project(*projections) # FIXME: converting these to SQLLiterals is probably not good, but # rails tests require it. @ctx.projections.concat projections.map! { |x| STRING_OR_SYMBOL_CLASS.include?(x.class) ? Nodes::SqlLiteral.new(x.to_s) : x } self end
#skip(amount) Also known as: #offset=
[ GitHub ]#source
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 270
def source @ctx.source end
#take(limit) Also known as: #limit=
[ GitHub ]#taken
Alias for #limit.
# File 'activerecord/lib/arel/select_manager.rb', line 32
alias :taken :limit
#union(operation, other = nil)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 213
def union(operation, other = nil) if other unless operation.to_s.casecmp?("all") raise ArgumentError, "Unknown union operation: #{operation.inspect}" end node_class = Nodes::UnionAll else other = operation node_class = Nodes::Union end node_class.new self.ast, other.ast end
#where(expr)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 199
def where(expr) if Arel::TreeManager === expr expr = expr.ast end @ctx.wheres << expr self end
#where_sql(engine = Table.engine)
[ GitHub ]#window(name)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 139
def window(name) window = Nodes::NamedWindow.new(name) @ctx.windows.push window window end
#with(*subqueries)
[ GitHub ]# File 'activerecord/lib/arel/select_manager.rb', line 241
def with(*subqueries) if subqueries.first.is_a? Symbol operation = subqueries.shift unless operation.to_s.casecmp?("recursive") raise ArgumentError, "Unknown with operation: #{operation.inspect}" end node_class = Nodes::WithRecursive else node_class = Nodes::With end @ast.with = node_class.new(subqueries.flatten) self end