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.



10
11
12
13
# File 'lib/db/model/statement/limit.rb', line 10

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

Instance Method Details

#append_to(statement) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/db/model/statement/limit.rb', line 15

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



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

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