Namespace

Included Modules

Class Index [+]

Quicksearch

Arel::SelectManager

Public Class Methods

new(engine, table = nil) click to toggle source
    # File lib/arel/select_manager.rb, line 5
 5:     def initialize engine, table = nil
 6:       super(engine)
 7:       @ast   = Nodes::SelectStatement.new
 8:       @ctx    = @ast.cores.last
 9:       from table
10:     end

Public Instance Methods

constraints() click to toggle source
    # File lib/arel/select_manager.rb, line 16
16:     def constraints
17:       @ctx.wheres
18:     end
exists() click to toggle source
 

Produces an Arel::Nodes::Exists node

    # File lib/arel/select_manager.rb, line 27
27:     def exists
28:       Arel::Nodes::Exists.new @ast
29:     end
from(table) click to toggle source
    # File lib/arel/select_manager.rb, line 64
64:     def from table
65:       table = Nodes::SqlLiteral.new(table) if String === table
66:       # FIXME: this is a hack to support
67:       # test_with_two_tables_in_from_without_getting_double_quoted
68:       # from the AR tests.
69:       if @ctx.froms
70:         source = @ctx.froms
71: 
72:         if Nodes::SqlLiteral === table && Nodes::Join === source
73:           source.left = table
74:           table = source
75:         end
76:       end
77: 
78:       @ctx.froms = table
79:       self
80:     end
group(*columns) click to toggle source
    # File lib/arel/select_manager.rb, line 53
53:     def group *columns
54:       columns.each do |column|
55:         # FIXME: backwards compat
56:         column = Nodes::SqlLiteral.new(column) if String === column
57:         column = Nodes::SqlLiteral.new(column.to_s) if Symbol === column
58: 
59:         @ctx.groups.push Nodes::Group.new column
60:       end
61:       self
62:     end
having(expr) click to toggle source
    # File lib/arel/select_manager.rb, line 94
94:     def having expr
95:       expr = Nodes::SqlLiteral.new(expr) if String === expr
96: 
97:       @ctx.having = Nodes::Having.new(expr)
98:       self
99:     end
insert(values) click to toggle source

FIXME: this method should go away

     # File lib/arel/select_manager.rb, line 179
179:     def insert values
180:       im = InsertManager.new @engine
181:       table = @ctx.froms
182:       primary_key_name = (primary_key = table.primary_key) && primary_key.name
183:       # FIXME: in AR tests values sometimes were Array and not Hash therefore is_a?(Hash) check is added
184:       primary_key_value = primary_key && values.is_a?(Hash) && values[primary_key]
185:       im.into table
186:       im.insert values
187:       # Oracle adapter needs primary key name to generate RETURNING ... INTO ... clause
188:       # for tables which assign primary key value using trigger.
189:       # RETURNING ... INTO ... clause will be added only if primary_key_value is nil
190:       # therefore it is necessary to pass primary key value as well
191:       @engine.connection.insert im.to_sql, 'AREL', primary_key_name, primary_key_value
192:     end
join(relation, klass = Nodes::InnerJoin) click to toggle source
    # File lib/arel/select_manager.rb, line 82
82:     def join relation, klass = Nodes::InnerJoin
83:       return self unless relation
84: 
85:       case relation
86:       when String, Nodes::SqlLiteral
87:         raise if relation.blank?
88:         from Nodes::StringJoin.new(@ctx.froms, relation)
89:       else
90:         from klass.new(@ctx.froms, relation, nil)
91:       end
92:     end
join_sql() click to toggle source
     # File lib/arel/select_manager.rb, line 143
143:     def join_sql
144:       return nil unless @ctx.froms
145: 
146:       viz = Visitors::JoinSql.new @engine
147:       Nodes::SqlLiteral.new viz.accept @ctx
148:     end
joins(manager) click to toggle source
     # File lib/arel/select_manager.rb, line 156
156:     def joins manager
157:       manager.join_sql
158:     end
lock(locking = true) click to toggle source
    # File lib/arel/select_manager.rb, line 37
37:     def lock locking = true
38:       # FIXME: do we even need to store this?  If locking is +false+ shouldn't
39:       # we just remove the node from the AST?
40:       @ast.lock = Nodes::Lock.new
41:       self
42:     end
locked() click to toggle source
    # File lib/arel/select_manager.rb, line 44
44:     def locked
45:       @ast.lock
46:     end
on(*exprs) click to toggle source
    # File lib/arel/select_manager.rb, line 48
48:     def on *exprs
49:       @ctx.froms.constraint = Nodes::On.new(collapse(exprs))
50:       self
51:     end
order(*expr) click to toggle source
     # File lib/arel/select_manager.rb, line 115
115:     def order *expr
116:       # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
117:       @ast.orders.concat expr.map { |x|
118:         String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
119:       }
120:       self
121:     end
order_clauses() click to toggle source
     # File lib/arel/select_manager.rb, line 150
150:     def order_clauses
151:       Visitors::OrderClauses.new(@engine).accept(@ast).map { |x|
152:         Nodes::SqlLiteral.new x
153:       }
154:     end
orders() click to toggle source
     # File lib/arel/select_manager.rb, line 123
123:     def orders
124:       @ast.orders
125:     end
project(*projections) click to toggle source
     # File lib/arel/select_manager.rb, line 101
101:     def project *projections
102:       # FIXME: converting these to SQLLiterals is probably not good, but
103:       # rails tests require it.
104:       @ctx.projections.concat projections.map { |x|
105:         [Symbol, String].include?(x.class) ? SqlLiteral.new(x.to_s) : x
106:       }
107:       self
108:     end
skip(amount) click to toggle source
    # File lib/arel/select_manager.rb, line 20
20:     def skip amount
21:       @ast.offset = Nodes::Offset.new(amount)
22:       self
23:     end
take(limit) click to toggle source
     # File lib/arel/select_manager.rb, line 138
138:     def take limit
139:       @ast.limit = limit
140:       self
141:     end
taken() click to toggle source
    # File lib/arel/select_manager.rb, line 12
12:     def taken
13:       @ast.limit
14:     end
where(expr) click to toggle source
     # File lib/arel/select_manager.rb, line 110
110:     def where expr
111:       @ctx.wheres << expr
112:       self
113:     end
where_clauses() click to toggle source
    # File lib/arel/select_manager.rb, line 31
31:     def where_clauses
32:       #warn "where_clauses is deprecated" if $VERBOSE
33:       to_sql = Visitors::ToSql.new @engine
34:       @ctx.wheres.map { |c| to_sql.accept c }
35:     end
where_sql() click to toggle source
     # File lib/arel/select_manager.rb, line 131
131:     def where_sql
132:       return if @ctx.wheres.empty?
133: 
134:       viz = Visitors::WhereSql.new @engine
135:       Nodes::SqlLiteral.new viz.accept @ctx
136:     end
wheres() click to toggle source
     # File lib/arel/select_manager.rb, line 127
127:     def wheres
128:       Compatibility::Wheres.new @engine, @ctx.wheres
129:     end

Private Instance Methods

collapse(exprs) click to toggle source
     # File lib/arel/select_manager.rb, line 195
195:     def collapse exprs
196:       return exprs.first if exprs.length == 1
197: 
198:       right = exprs.pop
199:       left  = exprs.pop
200: 
201:       right = Nodes::SqlLiteral.new(right) if String === right
202: 
203:       right = Nodes::And.new left, right
204:       exprs.reverse.inject(right) { |memo,expr|
205:         Nodes::And.new(expr, memo)
206:       }
207:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.