diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 20:30:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-08 20:30:40 -0700 |
commit | 03e2006ad97cabb689e2a84bdbf9300baaf518b5 (patch) | |
tree | e913a62f12fb1c2955af143cb004ab4ab7b8d3ad /lib/arel/visitors | |
parent | 8fc2241df61ce274b652fae09e4640a50a500af7 (diff) | |
download | rails-03e2006ad97cabb689e2a84bdbf9300baaf518b5.tar.gz rails-03e2006ad97cabb689e2a84bdbf9300baaf518b5.tar.bz2 rails-03e2006ad97cabb689e2a84bdbf9300baaf518b5.zip |
refactor mssql nodes to move away from string interpolation
Diffstat (limited to 'lib/arel/visitors')
-rw-r--r-- | lib/arel/visitors/mssql.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/arel/visitors/mssql.rb b/lib/arel/visitors/mssql.rb index ef0b78058e..cc077d863b 100644 --- a/lib/arel/visitors/mssql.rb +++ b/lib/arel/visitors/mssql.rb @@ -1,6 +1,14 @@ module Arel module Visitors class MSSQL < Arel::Visitors::ToSql + class RowNumber + attr_reader :expr + + def initialize node + @expr = node + end + end + private # `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate @@ -10,6 +18,10 @@ module Arel "" end + def visit_Arel_Visitors_MSSQL_RowNumber o + "ROW_NUMBER() OVER (#{o.expr}) as _row_num" + end + def visit_Arel_Nodes_SelectStatement o if !o.limit && !o.offset return super o @@ -55,7 +67,7 @@ module Arel end def row_num_literal order_by - Nodes::SqlLiteral.new("ROW_NUMBER() OVER (#{order_by}) as _row_num") + RowNumber.new order_by end def select_count? x |