提交 5c9d75db 编写于 作者: A Aaron Patterson

adding locking node to the AST

上级 539572f0
......@@ -4,6 +4,7 @@
require 'arel/nodes/and'
require 'arel/nodes/in'
require 'arel/nodes/lock'
require 'arel/nodes/function'
require 'arel/nodes/count'
require 'arel/nodes/sum'
......
module Arel
module Nodes
class Lock
end
end
end
......@@ -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
......
......@@ -8,6 +8,13 @@ def initialize engine
@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
......
......@@ -26,6 +26,10 @@ def tm
SelectManager.new(@engine).from(self)
end
def from table
SelectManager.new(@engine).from table
end
def joins manager
nil
end
......
......@@ -48,7 +48,8 @@ def visit_Arel_Nodes_SelectStatement o
[
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 @@ def visit_Arel_Nodes_Having o
"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
......
......@@ -25,6 +25,15 @@ def execute sql, name = nil
end
describe 'select manager' do
describe 'lock' do
# This should fail on other databases
it 'adds a lock node' do
table = Table.new :users
mgr = table.from table
mgr.lock.to_sql.should be_like %{ SELECT FROM "users" }
end
end
describe 'order' do
it 'generates order clauses' do
table = Table.new :users
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册