Skip to content

Right PHP type for pgsql arrays#153

Closed
Gerych1984 wants to merge 4 commits into
yiisoft:masterfrom
Gerych1984:pgsql-array-type
Closed

Right PHP type for pgsql arrays#153
Gerych1984 wants to merge 4 commits into
yiisoft:masterfrom
Gerych1984:pgsql-array-type

Conversation

@Gerych1984

@Gerych1984 Gerych1984 commented Oct 2, 2022

Copy link
Copy Markdown
Contributor
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

@codecov

codecov Bot commented Oct 4, 2022

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 80.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.55%. Comparing base (3c66aea) to head (5d92994).
Report is 196 commits behind head on master.

Files with missing lines Patch % Lines
src/ColumnSchema.php 78.57% 6 Missing ⚠️
src/ArrayParser.php 83.33% 2 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Tigrov

Tigrov commented Jan 3, 2023

Copy link
Copy Markdown
Member

What's wrong with the current type casting?

array_walk_recursive($value, function (?string &$val) {

protected function phpTypecastValue($value)

@Gerych1984

Gerych1984 commented Jan 4, 2023

Copy link
Copy Markdown
Contributor Author

What's wrong with the current type casting?

array_walk_recursive($value, function (?string &$val) {

protected function phpTypecastValue($value)

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*/

@Tigrov

Tigrov commented Jan 4, 2023

Copy link
Copy Markdown
Member

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

@Tigrov

Tigrov commented Dec 26, 2024

Copy link
Copy Markdown
Member

Speed of type casting array values was improved by #315

@Tigrov Tigrov closed this Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants