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

Right PHP type for pgsql arrays #153

Closed
wants to merge 4 commits into from

Conversation

Gerych1984
Copy link

@Gerych1984 Gerych1984 commented Oct 2, 2022

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

codecov bot commented Oct 4, 2022

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
Copy link
Member

Tigrov commented Jan 3, 2023

What's wrong with the current type casting?

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

protected function phpTypecastValue($value)

@Gerych1984
Copy link
Author

Gerych1984 commented Jan 4, 2023

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
Copy link
Member

Tigrov commented Jan 4, 2023

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

@Tigrov
Copy link
Member

Tigrov commented Dec 26, 2024

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