Class: DB::Model::Statement::Limit

Inherits:
Object
  • Object
show all
Defined in:
lib/db/model/statement/limit.rb

Constant Summary collapse

ONE =
self.new(1)

Instance Method Summary collapse

Constructor Details

#initialize(count, offset: nil) ⇒ Limit

Returns a new instance of Limit.



27
28
29
30
# File 'lib/db/model/statement/limit.rb', line 27

def initialize(count, offset: nil)
  @count = count
  @offset = offset
end

Instance Method Details

#append_to(statement) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/db/model/statement/limit.rb', line 32

def append_to(statement)
  statement.clause("LIMIT")
  statement.literal(@count)
  
  if @offset
    statement.clause("OFFSET")
    statement.literal(@offset)
  end
  
  return statement
end

#first(count) ⇒ Object



44
45
46
# File 'lib/db/model/statement/limit.rb', line 44

def first(count)
  self.new(count, offset: @offset)
end