Skip to content

Commit

Permalink
Add support for Doctrine DBAL 4
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd committed Feb 8, 2024
1 parent a767a1e commit 16e878e
Show file tree
Hide file tree
Showing 31 changed files with 188 additions and 146 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ jobs:
- name: "Test"
run: "composer test"
env:
PGSQL_DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?serverVersion=11&charset=utf8
PGSQL_DATABASE_URL: pgsql://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?serverVersion=11&charset=utf8
MYSQL_DATABASE_URL: mysql://mysql:mysql@127.0.0.1:${{ job.services.mysql.ports[3306] }}/mysql
FLOW_LOCAL_FILESYSTEM_CACHE_DIR: "./var/cache/${{ matrix.php-version }}-${{ matrix.dependencies }}"

- name: "Run Examples"
run: "php examples/run.php"
run: "php examples/run.php"
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-zlib": "*",
"composer-runtime-api": "^2.1",
"coduo/php-humanizer": "^4.0",
"doctrine/dbal": "^3.6",
"doctrine/dbal": "^3.6 || ^4.0",
"elasticsearch/elasticsearch": "^7.6|^8.0",
"flix-tech/avro-php": "~4.2.0 || ~4.3.0",
"google/apiclient": "^2.13",
Expand Down
88 changes: 48 additions & 40 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</report>
</coverage>
<php>
<env name="PGSQL_DATABASE_URL" value="postgresql://postgres:postgres@127.0.0.1:5432/postgres?serverVersion=11%26charset=utf8"/>
<env name="PGSQL_DATABASE_URL" value="pgsql://postgres:postgres@127.0.0.1:5432/postgres?serverVersion=11%26charset=utf8"/>
<env name="MYSQL_DATABASE_URL" value="mysql://mysql:mysql@127.0.0.1:3306/mysql"/>
<env name="SQLITE_DATABASE_URL" value="sqlite:///:memory:"/>
<env name="ELASTICSEARCH_URL" value="localhost:9200"/>
Expand Down
1 change: 1 addition & 0 deletions src/adapter/etl-adapter-doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"doctrine/dbal": "^3.6 || ^4.0",
"flow-php/doctrine-dbal-bulk": "^0.5.0 || 1.x-dev",
"flow-php/etl": "^0.5.0 || 1.x-dev"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function from(Rows $rows) : DataFrame
}
}

/** @psalm-suppress InvalidArgument */
return (new Flow())->extract(\Flow\ETL\Adapter\Doctrine\dbal_from_query($this->connection(), $this->query, $parameters, $types));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function table(
}

$queryBuilder = $connection->createQueryBuilder()
->select($table->columns ?: '*')
->select(...$table->columns ?: ['*'])
->from($table->name);

foreach ($orderBy as $order) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
namespace Flow\ETL\Adapter\Doctrine;

use function Flow\ETL\DSL\array_to_rows;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use Flow\ETL\Extractor;
use Flow\ETL\FlowContext;

final class DbalQueryExtractor implements Extractor
{
/**
* @var ParametersSet
*/
private readonly ParametersSet $parametersSet;

/**
* @param null|ParametersSet $parametersSet
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types
* @param array<int|string, ArrayParameterType|int|ParameterType|string|Type> $types
*/
public function __construct(
private readonly Connection $connection,
Expand All @@ -32,7 +30,7 @@ public function __construct(

/**
* @param array<string, mixed>|list<mixed> $parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types
* @param array<int|string, ArrayParameterType|int|ParameterType|string|Type> $types
*/
public static function single(Connection $connection, string $query, array $parameters = [], array $types = []) : self
{
Expand All @@ -42,6 +40,11 @@ public static function single(Connection $connection, string $query, array $para
public function extract(FlowContext $context) : \Generator
{
foreach ($this->parametersSet->all() as $parameters) {
/**
* @phpstan-ignore-next-line
*
* @psalm-suppress InvalidArgument
*/
foreach ($this->connection->fetchAllAssociative($this->query, $parameters, $this->types) as $row) {
$signal = yield array_to_rows($row, $context->entryFactory());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

namespace Flow\ETL\Adapter\Doctrine;

use Doctrine\DBAL\ArrayParameterType;
use Flow\ETL\Rows;

final class LiteralParameter implements QueryParameter
{
public function __construct(
public readonly string $queryParamName,
public readonly mixed $value,
public readonly ?int $type = null
private readonly string $queryParamName,
private readonly mixed $value,
private readonly int|ArrayParameterType|null $type = null
) {
}

Expand All @@ -25,7 +26,7 @@ public function toQueryParam(Rows $rows) : mixed
return $this->value;
}

public function type() : ?int
public function type() : int|ArrayParameterType|null
{
return $this->type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
final class Parameter implements QueryParameter
{
public function __construct(
public readonly string $queryParamName,
public readonly EntryReference $ref,
public readonly int $type = ArrayParameterType::STRING,
private readonly string $queryParamName,
private readonly EntryReference $ref,
private readonly int|ArrayParameterType $type = ArrayParameterType::STRING,
) {
}

Expand Down Expand Up @@ -42,7 +42,7 @@ public function toQueryParam(Rows $rows) : mixed
return $rows->reduceToArray($this->ref);
}

public function type() : ?int
public function type() : int|ArrayParameterType|null
{
return $this->type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

namespace Flow\ETL\Adapter\Doctrine;

use Doctrine\DBAL\ArrayParameterType;
use Flow\ETL\Rows;

interface QueryParameter
{
public function queryParamName() : string;

/**
* @return null|array<array-key, null|bool|float|int|string>|bool|float|int|string
*/
public function toQueryParam(Rows $rows) : mixed;

public function type() : ?int;
public function type() : int|ArrayParameterType|null;
}
Loading

0 comments on commit 16e878e

Please sign in to comment.