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

as(other) click to toggle source
    # File lib/arel/select_manager.rb, line 46
46:     def as other
47:       create_table_alias grouping(@ast), Nodes::SqlLiteral.new(other)
48:     end
constraints() click to toggle source
    # File lib/arel/select_manager.rb, line 22
22:     def constraints
23:       @ctx.wheres
24:     end
distinct(value = true) click to toggle source
     # File lib/arel/select_manager.rb, line 142
142:     def distinct(value = true)
143:       if value
144:         @ctx.set_quantifier = Arel::Nodes::Distinct.new
145:       else
146:         @ctx.set_quantifier = nil
147:       end
148:     end
except(other) click to toggle source
     # File lib/arel/select_manager.rb, line 189
189:     def except other
190:       Nodes::Except.new ast, other.ast
191:     end
Also aliased as: minus
exists() click to toggle source
 

Produces an Arel::Nodes::Exists node

    # File lib/arel/select_manager.rb, line 42
42:     def exists
43:       Arel::Nodes::Exists.new @ast
44:     end
from(table) click to toggle source
     # File lib/arel/select_manager.rb, line 91
 91:     def from table
 92:       table = Nodes::SqlLiteral.new(table) if String === table
 93:       # FIXME: this is a hack to support
 94:       # test_with_two_tables_in_from_without_getting_double_quoted
 95:       # from the AR tests.
 96: 
 97:       case table
 98:       when Nodes::Join
 99:         @ctx.source.right << table
100:       else
101:         @ctx.source.left = table
102:       end
103: 
104:       self
105:     end
froms() click to toggle source
     # File lib/arel/select_manager.rb, line 107
107:     def froms
108:       @ast.cores.map { |x| x.from }.compact
109:     end
group(*columns) click to toggle source
    # File lib/arel/select_manager.rb, line 80
80:     def group *columns
81:       columns.each do |column|
82:         # FIXME: backwards compat
83:         column = Nodes::SqlLiteral.new(column) if String === column
84:         column = Nodes::SqlLiteral.new(column.to_s) if Symbol === column
85: 
86:         @ctx.groups.push Nodes::Group.new column
87:       end
88:       self
89:     end
having(*exprs) click to toggle source
     # File lib/arel/select_manager.rb, line 124
124:     def having *exprs
125:       @ctx.having = Nodes::Having.new(collapse(exprs, @ctx.having))
126:       self
127:     end
initialize_copy(other) click to toggle source
    # File lib/arel/select_manager.rb, line 12
12:     def initialize_copy other
13:       super
14:       @ctx = @ast.cores.last
15:     end
insert(values) click to toggle source

FIXME: this method should go away

     # File lib/arel/select_manager.rb, line 266
266:     def insert values
267:       if $VERBOSE
268:         warn insert (#{caller.first}) is deprecated and will be removed in ARel 4.0.0. Pleaseswitch to `compile_insert`
269:       end
270: 
271:       im = compile_insert(values)
272:       table = @ctx.froms
273: 
274:       primary_key      = table.primary_key
275:       primary_key_name = primary_key.name if primary_key
276: 
277:       # FIXME: in AR tests values sometimes were Array and not Hash therefore is_a?(Hash) check is added
278:       primary_key_value = primary_key && values.is_a?(Hash) && values[primary_key]
279:       im.into table
280:       # Oracle adapter needs primary key name to generate RETURNING ... INTO ... clause
281:       # for tables which assign primary key value using trigger.
282:       # RETURNING ... INTO ... clause will be added only if primary_key_value is nil
283:       # therefore it is necessary to pass primary key value as well
284:       @engine.connection.insert im.to_sql, 'AREL', primary_key_name, primary_key_value
285:     end
intersect(other) click to toggle source
     # File lib/arel/select_manager.rb, line 185
185:     def intersect other
186:       Nodes::Intersect.new ast, other.ast
187:     end
join(relation, klass = Nodes::InnerJoin) click to toggle source
     # File lib/arel/select_manager.rb, line 111
111:     def join relation, klass = Nodes::InnerJoin
112:       return self unless relation
113: 
114:       case relation
115:       when String, Nodes::SqlLiteral
116:         raise if relation.blank?
117:         klass = Nodes::StringJoin
118:       end
119: 
120:       @ctx.source.right << create_join(relation, nil, klass)
121:       self
122:     end
join_sources() click to toggle source
     # File lib/arel/select_manager.rb, line 231
231:     def join_sources
232:       @ctx.source.right
233:     end
join_sql() click to toggle source
     # File lib/arel/select_manager.rb, line 217
217:     def join_sql
218:       return nil if @ctx.source.right.empty?
219: 
220:       sql = visitor.dup.extend(Visitors::JoinSql).accept @ctx
221:       Nodes::SqlLiteral.new sql
222:     end
joins(manager) click to toggle source
     # File lib/arel/select_manager.rb, line 239
239:     def joins manager
240:       if $VERBOSE
241:         warn "joins is deprecated and will be removed in 4.0.0"
242:         warn "please remove your call to joins from #{caller.first}"
243:       end
244:       manager.join_sql
245:     end
limit() click to toggle source
    # File lib/arel/select_manager.rb, line 17
17:     def limit
18:       @ast.limit && @ast.limit.expr
19:     end
Also aliased as: taken
limit=(limit) click to toggle source
Alias for: take
lock(locking = Arel.sql('FOR UPDATE')) click to toggle source
    # File lib/arel/select_manager.rb, line 58
58:     def lock locking = Arel.sql('FOR UPDATE')
59:       case locking
60:       when true
61:         locking = Arel.sql('FOR UPDATE')
62:       when Arel::Nodes::SqlLiteral
63:       when String
64:         locking = Arel.sql locking
65:       end
66: 
67:       @ast.lock = Nodes::Lock.new(locking)
68:       self
69:     end
locked() click to toggle source
    # File lib/arel/select_manager.rb, line 71
71:     def locked
72:       @ast.lock
73:     end
minus(other) click to toggle source
Alias for: except
offset() click to toggle source
    # File lib/arel/select_manager.rb, line 26
26:     def offset
27:       @ast.offset && @ast.offset.expr
28:     end
offset=(amount) click to toggle source
Alias for: skip
on(*exprs) click to toggle source
    # File lib/arel/select_manager.rb, line 75
75:     def on *exprs
76:       @ctx.source.right.last.right = Nodes::On.new(collapse(exprs))
77:       self
78:     end
order(*expr) click to toggle source
     # File lib/arel/select_manager.rb, line 150
150:     def order *expr
151:       # FIXME: We SHOULD NOT be converting these to SqlLiteral automatically
152:       @ast.orders.concat expr.map { |x|
153:         String === x || Symbol === x ? Nodes::SqlLiteral.new(x.to_s) : x
154:       }
155:       self
156:     end
order_clauses() click to toggle source
     # File lib/arel/select_manager.rb, line 224
224:     def order_clauses
225:       visitor = Visitors::OrderClauses.new(@engine.connection)
226:       visitor.accept(@ast).map { |x|
227:         Nodes::SqlLiteral.new x
228:       }
229:     end
orders() click to toggle source
     # File lib/arel/select_manager.rb, line 158
158:     def orders
159:       @ast.orders
160:     end
project(*projections) click to toggle source
     # File lib/arel/select_manager.rb, line 129
129:     def project *projections
130:       # FIXME: converting these to SQLLiterals is probably not good, but
131:       # rails tests require it.
132:       @ctx.projections.concat projections.map { |x|
133:         [Symbol, String].include?(x.class) ? SqlLiteral.new(x.to_s) : x
134:       }
135:       self
136:     end
projections=(projections) click to toggle source
     # File lib/arel/select_manager.rb, line 138
138:     def projections= projections
139:       @ctx.projections = projections
140:     end
skip(amount) click to toggle source
    # File lib/arel/select_manager.rb, line 30
30:     def skip amount
31:       if amount
32:         @ast.offset = Nodes::Offset.new(amount)
33:       else
34:         @ast.offset = nil
35:       end
36:       self
37:     end
Also aliased as: offset=
source() click to toggle source
     # File lib/arel/select_manager.rb, line 235
235:     def source
236:       @ctx.source
237:     end
take(limit) click to toggle source
     # File lib/arel/select_manager.rb, line 205
205:     def take limit
206:       if limit
207:         @ast.limit = Nodes::Limit.new(limit)
208:         @ctx.top   = Nodes::Top.new(limit)
209:       else
210:         @ast.limit = nil
211:         @ctx.top   = nil
212:       end
213:       self
214:     end
Also aliased as: limit=
taken() click to toggle source
Alias for: limit
union(operation, other = nil) click to toggle source
     # File lib/arel/select_manager.rb, line 174
174:     def union operation, other = nil
175:       if other
176:         node_class = Nodes.const_get("Union#{operation.to_s.capitalize}")
177:       else
178:         other = operation
179:         node_class = Nodes::Union
180:       end
181: 
182:       node_class.new self.ast, other.ast
183:     end
where_clauses() click to toggle source
    # File lib/arel/select_manager.rb, line 50
50:     def where_clauses
51:       if $VERBOSE
52:         warn "(#{caller.first}) where_clauses is deprecated and will be removed in arel 4.0.0 with no replacement"
53:       end
54:       to_sql = Visitors::ToSql.new @engine.connection
55:       @ctx.wheres.map { |c| to_sql.accept c }
56:     end
where_sql() click to toggle source
     # File lib/arel/select_manager.rb, line 167
167:     def where_sql
168:       return if @ctx.wheres.empty?
169: 
170:       viz = Visitors::WhereSql.new @engine.connection
171:       Nodes::SqlLiteral.new viz.accept @ctx
172:     end
wheres() click to toggle source
     # File lib/arel/select_manager.rb, line 162
162:     def wheres
163:       warn "#{caller[0]}: SelectManager#wheres is deprecated and will be removed in ARel 4.0.0 with no replacement"
164:       Compatibility::Wheres.new @engine.connection, @ctx.wheres
165:     end
with(*subqueries) click to toggle source
     # File lib/arel/select_manager.rb, line 194
194:     def with *subqueries
195:       if subqueries.first.is_a? Symbol
196:         node_class = Nodes.const_get("With#{subqueries.shift.to_s.capitalize}")
197:       else
198:         node_class = Nodes::With
199:       end
200:       @ast.with = node_class.new(subqueries.flatten)
201: 
202:       self
203:     end

Private Instance Methods

collapse(exprs, existing = nil) click to toggle source
     # File lib/arel/select_manager.rb, line 291
291:     def collapse exprs, existing = nil
292:       exprs = exprs.unshift(existing.expr) if existing
293:       exprs = exprs.compact.map { |expr|
294:         if String === expr
295:           # FIXME: Don't do this automatically
296:           Arel.sql(expr)
297:         else
298:           expr
299:         end
300:       }
301: 
302:       if exprs.length == 1
303:         exprs.first
304:       else
305:         create_and exprs
306:       end
307:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.