Skip to content

Commit fd5c097

Browse files
committed
feat(database): add count() helper to IsDatabaseQuery trait
1 parent 22dbe07 commit fd5c097

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Tempest/Database/src/IsDatabaseModel.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tempest\Database;
66

7+
use Tempest\Database\Builder\QueryBuilders\CountQueryBuilder;
78
use Tempest\Database\Builder\QueryBuilders\SelectQueryBuilder;
89
use Tempest\Database\Exceptions\MissingRelation;
910
use Tempest\Database\Exceptions\MissingValue;
@@ -60,6 +61,16 @@ public static function find(mixed ...$conditions): SelectQueryBuilder
6061
return $query;
6162
}
6263

64+
public static function count(): CountQueryBuilder
65+
{
66+
return query(self::class)->count();
67+
}
68+
69+
public static function countAll(): int
70+
{
71+
return query(self::class)->count()->execute();
72+
}
73+
6374
public static function create(mixed ...$params): self
6475
{
6576
model(self::class)->validate(...$params);

0 commit comments

Comments
 (0)