1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/lib/arel/nodes/unary.rb
Vladimir Kochnev 41b92914f8 Abandon TOP support.
Initially, `TOP` was introduced to support `limit` for MSSQL database.
Unlike PostgreSQL/MySQL/SQLite, MSSQL does not have native `LIMIT`/`OFFSET` support.
The commit adding `TOP` is 1a246f7161.

However, it figured out that `TOP` implementation was weak and it's not sufficient
to also support `OFFSET`, then `TOP` was substituted with
`ROW_NUMBER()` subquery in be48ed3071.
This is a well known trick in MSSQL -
https://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server.

So now we don't need this `visit_Arel_Nodes_Top` at all.
It does nothing useful but also adds an extra space after `SELECT` when `LIMIT` is being
used for **any** database.
2018-09-25 15:39:14 +04:00

44 lines
698 B
Ruby

# frozen_string_literal: true
module Arel # :nodoc: all
module Nodes
class Unary < Arel::Nodes::NodeExpression
attr_accessor :expr
alias :value :expr
def initialize(expr)
super()
@expr = expr
end
def hash
@expr.hash
end
def eql?(other)
self.class == other.class &&
self.expr == other.expr
end
alias :== :eql?
end
%w{
Bin
Cube
DistinctOn
Group
GroupingElement
GroupingSet
Lateral
Limit
Lock
Not
Offset
On
Ordering
RollUp
}.each do |name|
const_set(name, Class.new(Unary))
end
end
end