spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Implementing pagination? #220

Open charlesswanson opened 7 years ago

charlesswanson commented 7 years ago

I have a select query which limits the results to a count of 10. In raw mysqli, I can have "SELECT SQL_CALC_FOUND_ROWS * FROM table WHERE condition LIMIT 0,10", then perform another query to know how many total rows matched. SELECT FOUND_ROWS() as foundrows

It looks like doctrine supports something similar: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/pagination.html

Is this possible with spot2?

Thanks

nebulousGirl commented 7 years ago

There is nothing similar in Spot, but you could write a class that makes use of a Spot Query.

Spot aims to be a more lightweight alternative. So, I don't think that kind of class would make it to the core.

You can paginate your query yourself using limit(), offset() and count()

marcelloh commented 7 years ago

Which seems a strange asnwer, because I have this working in my code:

if ($limit)
{
    $result = $this->where($aFilter)
        ->order(['name' => 'ASC'])
        ->limit($limit, $offset);
}
else
{
    $result = $this->where($aFilter)
        ->order(['name' => 'ASC']);
}
tuupola commented 7 years ago

@marcelloh Which is exactly what @nebulousGirl answered.

You can paginate your query yourself using limit(), offset() and count()

Question was if Spot has is a Doctrine style paginator. Which Spot does not have.

vlucas commented 7 years ago

Honestly I would not be opposed to a simplistic Pagination class that uses the built-in limit() offset() and count() methods to make things easier.

tuupola commented 7 years ago

I did something like that a while ago.

https://github.com/tuupola/beeper

tuupola commented 7 years ago

Personally I do not think this belongs in core. However thanks to being an organisation we could make something like spotorm/paginator.