aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/select_manager.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/select_manager.rb')
-rw-r--r--lib/arel/select_manager.rb37
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 0fa344945e..7f533fa91b 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -18,10 +18,19 @@ module Arel
@ctx.wheres
end
+ def offset
+ @ast.offset && @ast.offset.expr
+ end
+
def skip amount
- @ast.offset = Nodes::Offset.new(amount)
+ if amount
+ @ast.offset = Nodes::Offset.new(amount)
+ else
+ @ast.offset = nil
+ end
self
end
+ alias :offset= :skip
###
# Produces an Arel::Nodes::Exists node
@@ -37,10 +46,16 @@ module Arel
@ctx.wheres.map { |c| to_sql.accept c }
end
- def lock locking = true
- # FIXME: do we even need to store this? If locking is +false+ shouldn't
- # we just remove the node from the AST?
- @ast.lock = Nodes::Lock.new
+ def lock locking = Arel.sql('FOR UPDATE')
+ case locking
+ when true
+ locking = Arel.sql('FOR UPDATE')
+ when Arel::Nodes::SqlLiteral
+ when String
+ locking = Arel.sql locking
+ end
+
+ @ast.lock = Nodes::Lock.new(locking)
self
end
@@ -161,13 +176,21 @@ module Arel
node_class = Nodes::With
end
@ast.with = node_class.new(subqueries.flatten)
+
+ self
end
def take limit
- @ast.limit = Nodes::Limit.new(limit)
- @ctx.top = Nodes::Top.new(limit)
+ if limit
+ @ast.limit = Nodes::Limit.new(limit)
+ @ctx.top = Nodes::Top.new(limit)
+ else
+ @ast.limit = nil
+ @ctx.top = nil
+ end
self
end
+ alias limit= take
def join_sql
return nil if @ctx.source.right.empty?