Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db, count elements #277

Closed
mruz opened this issue Sep 2, 2020 · 0 comments · Fixed by #287
Closed

Db, count elements #277

mruz opened this issue Sep 2, 2020 · 0 comments · Fixed by #287
Labels

Comments

@mruz
Copy link
Member

mruz commented Sep 2, 2020

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;
    }
@mruz mruz added the feature label Sep 2, 2020
mruz added a commit to mruz/framework that referenced this issue Sep 23, 2020
@mruz mruz closed this as completed in #287 Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant