mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
refactor mssql nodes to move away from string interpolation
This commit is contained in:
parent
8fc2241df6
commit
03e2006ad9
1 changed files with 13 additions and 1 deletions
|
@ -1,6 +1,14 @@
|
||||||
module Arel
|
module Arel
|
||||||
module Visitors
|
module Visitors
|
||||||
class MSSQL < Arel::Visitors::ToSql
|
class MSSQL < Arel::Visitors::ToSql
|
||||||
|
class RowNumber
|
||||||
|
attr_reader :expr
|
||||||
|
|
||||||
|
def initialize node
|
||||||
|
@expr = node
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
|
# `top` wouldn't really work here. I.e. User.select("distinct first_name").limit(10) would generate
|
||||||
|
@ -10,6 +18,10 @@ module Arel
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def visit_Arel_Visitors_MSSQL_RowNumber o
|
||||||
|
"ROW_NUMBER() OVER (#{o.expr}) as _row_num"
|
||||||
|
end
|
||||||
|
|
||||||
def visit_Arel_Nodes_SelectStatement o
|
def visit_Arel_Nodes_SelectStatement o
|
||||||
if !o.limit && !o.offset
|
if !o.limit && !o.offset
|
||||||
return super o
|
return super o
|
||||||
|
@ -55,7 +67,7 @@ module Arel
|
||||||
end
|
end
|
||||||
|
|
||||||
def row_num_literal order_by
|
def row_num_literal order_by
|
||||||
Nodes::SqlLiteral.new("ROW_NUMBER() OVER (#{order_by}) as _row_num")
|
RowNumber.new order_by
|
||||||
end
|
end
|
||||||
|
|
||||||
def select_count? x
|
def select_count? x
|
||||||
|
|
Loading…
Reference in a new issue