aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/nodes.rb1
-rw-r--r--lib/arel/nodes/offset.rb11
-rw-r--r--lib/arel/nodes/select_statement.rb3
-rw-r--r--lib/arel/select_manager.rb5
-rw-r--r--lib/arel/visitors/to_sql.rb5
5 files changed, 24 insertions, 1 deletions
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 2894deab57..89e28f138c 100644
--- a/lib/arel/nodes.rb
+++ b/lib/arel/nodes.rb
@@ -8,6 +8,7 @@ require 'arel/nodes/lock'
require 'arel/nodes/function'
require 'arel/nodes/count'
require 'arel/nodes/values'
+require 'arel/nodes/offset'
require 'arel/nodes/sum'
require 'arel/nodes/max'
require 'arel/nodes/avg'
diff --git a/lib/arel/nodes/offset.rb b/lib/arel/nodes/offset.rb
new file mode 100644
index 0000000000..baa4068d93
--- /dev/null
+++ b/lib/arel/nodes/offset.rb
@@ -0,0 +1,11 @@
+module Arel
+ module Nodes
+ class Offset
+ attr_accessor :value
+
+ def initialize value
+ @value = value
+ end
+ end
+ end
+end
diff --git a/lib/arel/nodes/select_statement.rb b/lib/arel/nodes/select_statement.rb
index a96c02a545..6272fd126d 100644
--- a/lib/arel/nodes/select_statement.rb
+++ b/lib/arel/nodes/select_statement.rb
@@ -2,13 +2,14 @@ module Arel
module Nodes
class SelectStatement
attr_reader :cores
- attr_accessor :limit, :orders, :lock
+ attr_accessor :limit, :orders, :lock, :offset
def initialize cores = [SelectCore.new]
@cores = cores
@orders = []
@limit = nil
@lock = nil
+ @offset = nil
end
def initialize_copy other
diff --git a/lib/arel/select_manager.rb b/lib/arel/select_manager.rb
index 569b631c7f..ce749c4977 100644
--- a/lib/arel/select_manager.rb
+++ b/lib/arel/select_manager.rb
@@ -12,6 +12,11 @@ module Arel
@head.limit
end
+ def skip amount
+ @head.offset = Nodes::Offset.new(amount)
+ self
+ end
+
def where_clauses
warn "where_clauses is deprecated" if $VERBOSE
to_sql = Visitors::ToSql.new @engine
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index 25b7f005ea..d45253abd5 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -52,6 +52,7 @@ 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),
+ (visit(o.offset) if o.offset),
(visit(o.lock) if o.lock),
].compact.join ' '
end
@@ -70,6 +71,10 @@ module Arel
"HAVING #{visit o.expr}"
end
+ def visit_Arel_Nodes_Offset o
+ "OFFSET #{visit o.value}"
+ end
+
# FIXME: this does nothing on SQLLite3, but should do things on other
# databases.
def visit_Arel_Nodes_Lock o