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
fetchGroup() #87
fetchGroup() #87
Conversation
| @@ -57,7 +57,7 @@ Alternatively, [download a release](https://github.com/auraphp/Aura.Sql/releases | |||
| [](https://scrutinizer-ci.com/g/auraphp/Aura.Sql/) | |||
| [](https://travis-ci.org/auraphp/Aura.Sql) | |||
|
|
|||
| To run the unit tests at the command line, issue `phpunit -c tests/unit/`. (This requires [PHPUnit][] to be available as `phpunit`.) | |||
| To run the unit tests at the command line, issue `composer test`. (This requires [PHPUnit][] to be available as `phpunit`.) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach. But the problem is Aura.Sql is truly standalone and people don't need composer for testing :) .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who doesn't use composer?! 😄
|
Here are examples for the same exact query, and how the results are returned for different fetch strategies. This is the query: $res = $this->db
->select()
->cols([
'fooId',
'id'
])
->from('foobar')
->where('fooId in(:in)')
->bindValue('in', $in)
->fetchAll();and this is the table: FetchAll()FetchAssoc()FetchGroup()Notice how only foreach ($entity as $e) {
$e->children = isset($results[$e->id]) ? $results[$e->id] : [];
} |
|
I like it. Essentially it exposes PDO::FETCH_GROUP as a method. If you make these two changes, I can merge it directly:
Aside from that, very nice, and good testing. |
|
Sorry, testing leaked in from a different branch. Will remove. |
|
Gotcha. As a matter of principle, boolean params are not great. Two options:
Option 2 is the probably better plan if there are only two useful FETCH_* styles. If there are more than two, Option 1 is probably the better plan. |
|
How is fetchGroup() and fetchGroupMultiple()? |
|
The comments at http://php.net/manual/en/pdostatement.fetchall.php lead me to believe that there are more valid FETCH_* styles than just those two (e.g., http://php.net/manual/en/pdostatement.fetchall.php#88699). That makes me think Option 1 is the appropriate one here. |
|
I changed the third param to take a style and default to FETCH_COLUMN |
|
OK, now I need you to ... no, just kidding. |
Add fetchGroup() functionality.
|
thanks! Now for the test stuff - what's the best medium to discuss that? |
Add a
fetchGroup()fetch strategy that groups returned data by the first column. UnlikefetchAssoc(),fetchGroup()returns a much flatter set of values.Also added a test command (
composer test) and set some variables for phpunit.