fab2s / YaEtl

Yet Another ETL in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel unique key extractor and PDO type exceptions

gig745 opened this issue · comments

I had to make the following changes to get this working with Laravel. Specifically changing ?string to ?Builder.

diff vendor/fab2s/yaetl/src/Extractors/PdoUniqueKeyExtractor.php ../YaEtl-2.0.0/src/Extractors/PdoUniqueKeyExtractor.php
14d13
< use Illuminate\Database\Query\Builder;
29c28
< * @param Builder|null $extractQuery

 * @param string|null  $extractQuery

53c52
< public function __construct(\PDO $pdo, ?Builder $extractQuery = null, $uniqueKey = 'id')

public function __construct(\PDO $pdo, ?string $extractQuery = null, $uniqueKey = 'id')

126a126

diff vendor/fab2s/yaetl/src/Extractors/UniqueKeyExtractorAbstract.php ../YaEtl-2.0.0/src/Extractors/UniqueKeyExtractorAbstract.php
14d13
< use Illuminate\Database\Query\Builder;
94c93
< * @param Builder|null $extractQuery

 * @param string|null  $extractQuery

117c116
< public function __construct(?Builder $extractQuery = null, $uniqueKeySetup = 'id')

public function __construct(?string $extractQuery = null, $uniqueKeySetup = 'id')
commented

Hello,

You are right, this one does not work as expected. Thanks for reporting, I will soon update it.

commented

I just had a look and it seems to me that the best strategy would be to just call setExtractQuery before the parent call and in the constructor like it is done with the regular LaravelExtractor. I cannot test right now, but replacing :

    public function __construct(Builder $extractQuery, $uniqueKey = 'id')
    {
        parent::__construct($extractQuery->getConnection()->getPdo(), $extractQuery, $uniqueKey);
    }

with

   public function __construct(Builder $extractQuery, $uniqueKey = 'id')
   {
       $this->setExtractQuery($extractQuery);

       parent::__construct($extractQuery->getConnection()->getPdo(), null, $uniqueKey);
   }

in src/Laravel/Extractors/UniqueKeyExtractor.php should do it.

Thank you. I was considering forking to fix this, but it looks like you are actively maintaining the project. Appreciate it!