aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes.rb1
-rw-r--r--lib/arel/nodes/lock.rb6
-rw-r--r--lib/arel/nodes/select_statement.rb3
-rw-r--r--lib/arel/select_manager.rb7
-rw-r--r--lib/arel/table.rb4
-rw-r--r--lib/arel/visitors/to_sql.rb8
6 files changed, 27 insertions, 2 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 8e11760c18..3d73de2f7a 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -4,6 +4,7 @@ require 'arel/nodes/or'
require 'arel/nodes/and'
require 'arel/nodes/in'
+require 'arel/nodes/lock'
require 'arel/nodes/function'
require 'arel/nodes/count'
require 'arel/nodes/sum'
diff --git a/lib/arel/nodes/lock.rb b/lib/arel/nodes/lock.rb
new file mode 100644
index 0000000000..3c7a72273f
--- /dev/null
+++ b/lib/arel/nodes/lock.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class Lock
+ end
+ end
+end
diff --git a/lib/arel/nodes/select_statement.rb b/lib/arel/nodes/select_statement.rb
index b7c59da275..a96c02a545 100644
--- a/lib/arel/nodes/select_statement.rb
+++ b/lib/arel/nodes/select_statement.rb
@@ -2,12 +2,13 @@ module Arel
module Nodes
class SelectStatement
attr_reader :cores
- attr_accessor :limit, :orders
+ attr_accessor :limit, :orders, :lock
def initialize cores = [SelectCore.new]
@cores = cores
@orders = []
@limit = nil
+ @lock = nil
end
def initialize_copy other
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 4ddae13aa4..bcfb1dc4eb 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -8,6 +8,13 @@ module Arel
@ctx = @head.cores.last
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?
+ @head.lock = Nodes::Lock.new
+ self
+ end
+
def on *exprs
@ctx.froms.last.constraint = Nodes::On.new(collapse(exprs))
self
diff --git a/lib/arel/table.rb b/lib/arel/table.rb
index ce21457e60..ac832ed2b3 100644
--- a/lib/arel/table.rb
+++ b/lib/arel/table.rb
@@ -26,6 +26,10 @@ module Arel
SelectManager.new(@engine).from(self)
end
+ def from table
+ SelectManager.new(@engine).from table
+ end
+
def joins manager
nil
end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 12967d27ad..0f2de092ea 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -48,7 +48,8 @@ module Arel
[
o.cores.map { |x| visit x }.join,
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
- ("LIMIT #{o.limit}" if o.limit)
+ ("LIMIT #{o.limit}" if o.limit),
+ (visit(o.lock) if o.lock),
].compact.join ' '
end
@@ -66,6 +67,11 @@ module Arel
"HAVING #{visit o.expr}"
end
+ # FIXME: this does nothing on SQLLite3, but should do things on other
+ # databases.
+ def visit_Arel_Nodes_Lock o
+ end
+
def visit_Arel_Nodes_Group o
visit o.expr
end