The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more
Teng::Plugin::Count - Count rows in database.
package MyDB;use parent qw/Teng/;__PACKAGE__->load_plugin('Count');package main;my $db = MyDB->new(...);$db->count('user'); # => The number of rows in 'user' table.$db->count('user', '*', {type => 2}); # => SELECT COUNT(*) FROM user WHERE type=2
package
MyDB;
use
parent
qw/Teng/
;
__PACKAGE__->load_plugin(
'Count'
);
main;
my
$db
= MyDB->new(...);
->count(
'user'
# => The number of rows in 'user' table.
,
'*'
, {
type
=> 2});
# => SELECT COUNT(*) FROM user WHERE type=2
This plugin provides shorthand for counting rows in database.
$table table name for counting
$column Column name for COUNT(...), the default value is '*'.
COUNT(...)
\%where : HashRef for creating where clause. The format is same as $db->select(). This parameter is optional.
$db->select()
Return: The number of rows.
To install Teng, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Teng
CPAN shell
perl -MCPAN -e shell install Teng
For more information on module installation, please visit the detailed CPAN module installation guide.