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



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/db/model/countable.rb', line 29

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)


43
44
45
# File 'lib/db/model/countable.rb', line 43

def empty?
	self.count == 0
end