mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
adding locking node to the AST
This commit is contained in:
parent
539572f023
commit
5c9d75db74
7 changed files with 36 additions and 2 deletions
|
@ -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'
|
||||
|
|
6
lib/arel/nodes/lock.rb
Normal file
6
lib/arel/nodes/lock.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
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 @@ 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -25,6 +25,15 @@ module Arel
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue