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

Possibility to override more Types through __construct($config) string #367

Closed
Ejsstiil opened this issue Jun 18, 2020 · 2 comments
Closed

Comments

@Ejsstiil
Copy link

Ejsstiil commented Jun 18, 2020

We can change only few types for normalize() behaviour.
JSON, DATE, DATETIME
like here:

Helpers::alias($config, 'result|formatDate', 'resultDate');
Helpers::alias($config, 'result|formatDateTime', 'resultDateTime');

  • Current problem

We don't have access to modify behaviour for the rest - namely for TIME and TIME_INTERVAL.

  1. MariaDB's TIME column become \DateInterval which is the problem i currently have.
    This block is hit even when column native type is "TIME":

    dibi/src/Dibi/Result.php

    Lines 493 to 496 in 70e940f

    } elseif ($type === Type::TIME_INTERVAL) {
    preg_match('#^(-?)(\d+)\D(\d+)\D(\d+)\z#', $value, $m);
    $row[$key] = new \DateInterval("PT$m[2]H$m[3]M$m[4]S");
    $row[$key]->invert = (int) (bool) $m[1];
  2. Also its not possible to call ->setFormat() or ->setType() when you using \Fluent unlike here:
    // using manual hints
    $res = $dibi->query('SELECT * FROM [customers]');
    $res->setType('customer_id', Type::INTEGER)
    ->setType('added', Type::DATETIME)
    ->setFormat(Type::DATETIME, 'Y-m-d H:i:s');
  • Explain your intentions.
  1. As title says - to able these to configure (or suppress) via constructor $config string.
    Add TIME and TIME_INTERVAL to configurable parameters and allow to set them to 's', // as 'string' to keep column as is.
	'lazy'     => '1',
	'charset'  => 'utf8',
	'result'   => ['formatDate' => 'Y-m-d', 'formatDateTime' => 'Y-m-d H:i:s', 'formatJson' => 'string', 
'formatTime' => 'string', 'formatTimeInterval' => 'string']

dibi/src/Dibi/Type.php

Lines 27 to 28 in 70e940f

TIME = 't',
TIME_INTERVAL = 'ti';

2. Maybe some another flag to disable normalizer() along with detectTypes() completellly
private function detectTypes(): void

and
private function normalize(array &$row): void

  • It's up to you to make a strong case to convince the project's developers of the merits of this feature.
    Not in every environment such auto-re-typing to PHP's types is useful and to conform the freedom Ill suggest this change.
@Ejsstiil
Copy link
Author

Any comment on this?

@dg
Copy link
Owner

dg commented Oct 8, 2020

I added options result > normalize to disable normalize, result > formatTimeInterval to affect interval format and option value 'native' to leave value as is.

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

No branches or pull requests

2 participants