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

Ability to disable normalization #214

Closed
mskocik opened this issue Jun 20, 2023 · 5 comments
Closed

Ability to disable normalization #214

mskocik opened this issue Jun 20, 2023 · 5 comments
Labels

Comments

@mskocik
Copy link

mskocik commented Jun 20, 2023

  • Is your feature request related to a problem? Please describe.

Sometimes is useful to get raw data from DB. For example I am exporting some data into CSV file. In current state of things can't simply pass $result->fetchAll() into CSVResponse (from Contributte). I need to iterate the array and convert Row to array first. And if there are DateTimes, need to convert them as well.
When exporting large datasets it's useless to convert to Row and to array again and stringify everything again.

  • Describe the solution you'd like.

It would be great if we can switch off data normalization. And even better if we could also get array<array> instead of array<Row>.

/** @var Row[] */
$denormalized = $result->raw()->fetchAll();

/** @var array<array> */
$arraysOfArray = $result->raw('array')->fetchAll();
  • Describe alternatives you've considered.

Alternative would be ability to provide custom Result class

@hrach
Copy link
Member

hrach commented Jun 20, 2023

Result has setValueNormalization(enabled: false) that's not enough? Array of array is probably to difficult to do without much added value.

@mskocik
Copy link
Author

mskocik commented Jun 20, 2023

I totally missed that method. 🤯🤦

Regarding array of array I was playing with it and Result could add new method (jus one) for that like this:

// Result.php
public function fetchAllAsArray(): array
{
    $data = [];
    while ($row = $this->adapter->fetch()) {
        $data[] = $this->normalize($row);
    }
    return $data;
}

@hrach
Copy link
Member

hrach commented Jun 20, 2023

And what's your motivation here to have an array? Why is it better than row?

@mskocik
Copy link
Author

mskocik commented Jun 20, 2023

As I wrote above: sometimes it's needed to work with arrays anyway, like using fputcsv where conversion to Row and then back to array is useless. Especially with large datasets.

But that would be only nice to have. Main point of this issue is solved by pointing me to setValueNormalization, so feel free to close the issue, if you don't consider array method useful. Workaround exists.

@mskocik
Copy link
Author

mskocik commented Oct 10, 2024

Regarding my last comment in #249 I am closing also this one, because it can be achieved the same way (by extending Result and so on...)

@mskocik mskocik closed this as completed Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants