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

Introduce fetch* methods in query builder #4489

Conversation

andrew-demb
Copy link
Contributor

Q A
Type feature
BC Break no
Fixed issues #4461

Summary

Added new fetch* methods (all non-deprecated fetch* methods from Connection class) to allow the use of better typing in fetching data.

Please let me know if I should write some tests and what to use in the description of the methods.

@morozov
Copy link
Member

morozov commented Feb 4, 2021

Please let me know if I should write some tests

Yes, please do. It could be a set of unit tests that all use the same QueryBuilder instance producing a couple of rows and a couple of columns and testing all the new methods. Something similar to ConverterTest.

[...] what to use in the description of the methods.

You can copy-paste the description of the corresponding Statement/Result methods or leave them empty.

@andrew-demb
Copy link
Contributor Author

It could be a set of unit tests that all use the same QueryBuilder instance producing a couple of rows and a couple of columns and testing all the new methods. Something similar to ConverterTest.

To be in sync - are you suggest a "fill" query builder with some data and use the mock connection with a strictly expected query to be bypassed to the needed method?

Example (expected query and other will be parametrized from data provider):

    protected function setUp(): void
    {
        $this->conn = $this->createMock(Connection::class);
    }

    public function testFetchAssociative(): void
    {
        $qb = new QueryBuilder($this->conn);

        $this->conn->expects($this->once())
            ->method('fetchAssociative')
            ->with('SELECT some FROM table');

        $qb->select('some')
            ->from('table')
            ->fetchAssociative();
    }

Thank you for help.

@morozov
Copy link
Member

morozov commented Feb 9, 2021

Yeah, the above looks good. You can also add the assertions that not only the query but the parameters and types are passed downstream, and the value returned by the statement is returned. This is as much as these new methods do.

@morozov
Copy link
Member

morozov commented Feb 9, 2021

As for the target branch, there's no plan to tag any new 2.x releases potentially with the exception of improving the upgrade path to 3.0. This improvement doesn't fall into the "upgrade path" category, so I believe it should target 3.1.x.

@andrew-demb andrew-demb changed the base branch from 2.12.x to 3.1.x February 19, 2021 21:34
@andrew-demb andrew-demb force-pushed the 4461-semantical-fetch-methods-query-builder branch 2 times, most recently from 9c80e69 to d8ce32a Compare February 19, 2021 21:44
@andrew-demb andrew-demb changed the title Introduce fetch* methods in query builder [WIP] Introduce fetch* methods in query builder Feb 19, 2021
@andrew-demb andrew-demb changed the title [WIP] Introduce fetch* methods in query builder Introduce fetch* methods in query builder Feb 19, 2021
@andrew-demb
Copy link
Contributor Author

Tests added.
Ready for review

@morozov
Copy link
Member

morozov commented Feb 19, 2021

Looks good, @andrew-demb. Please squash, and I can merge it. Or I can squash it before the merge.

@PowerKiKi
Copy link
Contributor

I think this PR lacks the addition of a new method executeStatement(), to be really complete. It could be done in a second PR, but I feel it would be more coherent to add all methods together, don't you think ?

@morozov morozov force-pushed the 4461-semantical-fetch-methods-query-builder branch from 6f4e141 to 0f9efe3 Compare February 20, 2021 20:22
@morozov
Copy link
Member

morozov commented Feb 20, 2021

I think this PR lacks the addition of a new method executeStatement(), to be really complete. It could be done in a second PR, but I feel it would be more coherent to add all methods together, don't you think ?

This PR doesn't deprecate anything so it's complete by just adding new methods. If you want to work on the deprecation, in addition to executeStatement() we'll need to add executeQuery() as well. Otherwise, there will be no way to obtain a Result from the built query.

@andrew-demb
Copy link
Contributor Author

@morozov thank you for squash

@PowerKiKi sorry, I missed your messages before. I think a new deprecation and more methods may require an additional discussion.
Lets do it in additional PR.

@morozov morozov merged commit 0cac077 into doctrine:3.1.x Feb 20, 2021
@andrew-demb andrew-demb deleted the 4461-semantical-fetch-methods-query-builder branch February 22, 2021 07:07
@morozov morozov linked an issue Feb 27, 2021 that may be closed by this pull request
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce fetch* methods in QueryBuilder for SELECT queries
3 participants