Right PHP type for pgsql arrays
| Q | A |
|---|---|
| Is bugfix? | ✔️ |
| New feature? | ❌ |
| Breaks BC? | ✔️ |
- Return
arrayasphpTypefor PgSql *[] columns - 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
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.
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
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*/
I suppose you should use your own implementation of ArrayParser for these tasks in your project.