Skip to content

Commit

Permalink
Merge pull request #5 from netlogix/bugfix/missing-mysql-platform-of-…
Browse files Browse the repository at this point in the history
…doctrine-2
  • Loading branch information
saschanowak authored Aug 22, 2024
2 parents 2c03ec8 + 7730849 commit 31efa89
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use RuntimeException;
Expand Down Expand Up @@ -121,22 +122,24 @@ protected function buildQuery(string $identifiers, string $columns, string $valu

return match (true) {
$platform instanceof PostgreSQLPlatform => <<<POSTGRESQL
INSERT INTO "{$this->table}" ({$columns})
VALUES ({$values})
ON CONFLICT ({$identifiers}) DO UPDATE SET {$updates}
POSTGRESQL
INSERT INTO "{$this->table}" ({$columns})
VALUES ({$values})
ON CONFLICT ({$identifiers}) DO UPDATE SET {$updates}
POSTGRESQL
,
$platform instanceof AbstractMySQLPlatform => <<<MYSQL
INSERT INTO {$this->table} ({$columns})
VALUES ({$values})
ON DUPLICATE KEY UPDATE {$updates}
MYSQL
,$platform instanceof SqlitePlatform => <<<SQLITE
INSERT INTO {$this->table} ({$columns})
VALUES ({$values})
ON CONFLICT({$identifiers}) DO UPDATE SET {$updates}
SQLITE
,default => throw new RuntimeException(
$platform instanceof AbstractMySQLPlatform || $platform instanceof MySqlPlatform => <<<MYSQL
INSERT INTO {$this->table} ({$columns})
VALUES ({$values})
ON DUPLICATE KEY UPDATE {$updates}
MYSQL
,
$platform instanceof SqlitePlatform => <<<SQLITE
INSERT INTO {$this->table} ({$columns})
VALUES ({$values})
ON CONFLICT({$identifiers}) DO UPDATE SET {$updates}
SQLITE
,
default => throw new RuntimeException(
sprintf('The database platform %s is not supported!', $platform::class),
1_603_199_935
)
Expand Down

0 comments on commit 31efa89

Please sign in to comment.