db-pgsql icon indicating copy to clipboard operation
db-pgsql copied to clipboard

Right PHP type for pgsql arrays

Open Gerych1984 opened this issue 3 years ago • 4 comments

Q A
Is bugfix? ✔️
New feature?
Breaks BC? ✔️

  1. Return array as phpType for PgSql *[] columns
  2. Allow type cast values in ArrayParser

P.S. maybe move all cast methods on new object? Something like TypeCaster etc. With they can be cast values wo double code

Gerych1984 avatar Oct 02 '22 18:10 Gerych1984

Codecov Report

Base: 97.09% // Head: 95.55% // Decreases project coverage by -1.53% :warning:

Coverage data is based on head (5d92994) compared to base (3c66aea). Patch coverage: 80.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #153      +/-   ##
============================================
- Coverage     97.09%   95.55%   -1.54%     
- Complexity      227      234       +7     
============================================
  Files            12       12              
  Lines           586      608      +22     
============================================
+ Hits            569      581      +12     
- Misses           17       27      +10     
Impacted Files Coverage Δ
src/Schema.php 97.45% <ø> (ø)
src/ColumnSchema.php 85.18% <78.57%> (-14.82%) :arrow_down:
src/ArrayParser.php 95.83% <83.33%> (-4.17%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Oct 04 '22 10:10 codecov[bot]

What's wrong with the current type casting?

https://github.com/yiisoft/db-pgsql/blob/3d47b9af600c807b981d25406ad7a02abac98ab7/src/ColumnSchema.php#L85

https://github.com/yiisoft/db-pgsql/blob/3d47b9af600c807b981d25406ad7a02abac98ab7/src/ColumnSchema.php#L107

Tigrov avatar Jan 03 '23 21:01 Tigrov

What's wrong with the current type casting?

https://github.com/yiisoft/db-pgsql/blob/3d47b9af600c807b981d25406ad7a02abac98ab7/src/ColumnSchema.php#L85

https://github.com/yiisoft/db-pgsql/blob/3d47b9af600c807b981d25406ad7a02abac98ab7/src/ColumnSchema.php#L107

There's nothing wrong with him. But sometimes you need to use it outside of schema/AR (for example in console command where you need to go through > 100000 rows, to reduce memory consumption). And in this case you have to cast it separately to php-type, because by default it returns array of strings. So as idea do it something like

$array = (new ArrayParser)->asInt()->parse($row['array_column'])

Instead of

$parsed = (new ArrayParser)->parse($row['array_column']);

$array = /* some double code do parse it as int array*/

Gerych1984 avatar Jan 04 '23 07:01 Gerych1984

I suppose you should use your own implementation of ArrayParser for these tasks in your project.

Tigrov avatar Jan 04 '23 15:01 Tigrov