whiteoctober / Pagerfanta

Pagination for PHP.
Other
1.59k stars 2 forks source link

Doctrine ORM Native Query Adapter #268

Closed tugrul closed 5 years ago

sampart commented 5 years ago

Hi @tugrul, thanks for getting involved!

Whilst I'm keen to make Pagerfanta as useful as possible by offering a good range of adapters, adding new ones does increase the maintenance overhead. Given that, please could you explain the sorts of things that this adapter makes possible that aren't possible with the existing Doctrine adapters? I think it's important to double-check this before adding a new one.

Once we've discussed the context and the need for this adapter, I should flag up that there'll be some additions to this PR required:

But I would hold off adding these to the PR until our bigger picture discussion has completed - I just wanted to give you a heads-up of possible work coming here.

Thanks again for contributing.

tugrul commented 5 years ago

I pushed a test case.

Doctrine has feature to map resultset of native queries.

https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/native-sql.html

But this feature accept raw queries. There is no feature to pass query builder. You can check it there.

https://www.doctrine-project.org/api/orm/latest/Doctrine/ORM/EntityManager.html#method_createNativeQuery https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/EntityManager.php#L306

https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/NativeQuery.php

But PagerFanta adapter needs to handle on query builder because it's going to put OFFSET and LIMIT sql clauses without broke the SQL dialect depended to DBMS.

In this adapter I used DBAL QueryBuilder to solve ORM NativeQuery raw SQL problem. I couldn't find more elegant way than this.

I thought to extend ORM NativeQuery class but it is final class and $sql member is private and doExecute method not calls the getSQL() getter method to obtain sql query.

https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/NativeQuery.php#L15