Permalink
Browse files

add locking support for postgres

  • Loading branch information...
1 parent d282903 commit d3625bbf8f22e9225f6568cd91caaea5cde903bd @tenderlove tenderlove committed Oct 13, 2010
Showing with 22 additions and 0 deletions.
  1. +1 −0 Manifest.txt
  2. +4 −0 lib/arel/visitors/postgresql.rb
  3. +17 −0 spec/visitors/postgres_spec.rb
View
1 Manifest.txt
@@ -102,4 +102,5 @@ spec/table_spec.rb
spec/update_manager_spec.rb
spec/visitors/join_sql_spec.rb
spec/visitors/oracle_spec.rb
+spec/visitors/postgres_spec.rb
spec/visitors/to_sql_spec.rb
View
4 lib/arel/visitors/postgresql.rb
@@ -2,6 +2,10 @@ module Arel
module Visitors
class PostgreSQL < Arel::Visitors::ToSql
private
+ def visit_Arel_Nodes_Lock o
+ "FOR UPDATE"
+ end
+
def visit_Arel_Nodes_SelectStatement o
if !o.orders.empty? && using_distinct_on?(o)
subquery = o.dup
View
17 spec/visitors/postgres_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+module Arel
+ module Visitors
+ describe 'the postgres visitor' do
+ before do
+ @visitor = PostgreSQL.new Table.engine
+ end
+
+ it 'should produce a lock value' do
+ @visitor.accept(Nodes::Lock.new).should be_like %{
+ FOR UPDATE
+ }
+ end
+ end
+ end
+end

0 comments on commit d3625bb

Please sign in to comment.