ice / framework

Source code of Ice framework
https://www.iceframework.org
BSD 3-Clause "New" or "Revised" License
341 stars 45 forks source link

Db, count elements #277

Closed mruz closed 4 years ago

mruz commented 4 years ago

Count elements to avoid fetching all.

For PDO we could use findOne and specify total as field:

public function count(array $filters = []): int
    {
        $result = $this->getDb()->findOne($this->model->from, $filters, [], ['count(*) AS total']);

        return $result ? (int) $result->total : 0;
    }