Module: DB::Model::Countable

Included in:
Relation, Where
Defined in:
lib/db/model/countable.rb

Instance Method Summary collapse

Instance Method Details

#count(fields = Statement::Count::ALL) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/db/model/countable.rb', line 12

def count(fields = Statement::Count::ALL)
	Statement::Select.new(@model,
		fields: fields,
		where: self.predicate,
	).to_sql(@context).call do |connection|
		result = connection.next_result
		
		row = result.to_a.first
		
		# Return the count:
		return row.first
	end
end

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/db/model/countable.rb', line 26

def empty?
	self.count == 0
end