Skip to content

Commit

Permalink
Optimized the database exception to implement unique constraint error…
Browse files Browse the repository at this point in the history
… detection. (#7194)
  • Loading branch information
huangdijia authored Dec 11, 2024
1 parent 725e7a4 commit 7bb3ae4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/PostgreSqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Hyperf\Database\PgSQL;

use Exception;
use Hyperf\Database\Connection;
use Hyperf\Database\PgSQL\DBAL\PostgresDriver;
use Hyperf\Database\PgSQL\Query\Grammars\PostgresGrammar as QueryGrammar;
Expand Down Expand Up @@ -48,6 +49,16 @@ public function bindValues(PDOStatement $statement, array $bindings): void
}
}

/**
* Determine if the given database exception was caused by a unique constraint violation.
*
* @return bool
*/
protected function isUniqueConstraintError(Exception $exception)
{
return $exception->getCode() === '23505';
}

/**
* Get the default query grammar instance.
* @return PostgresGrammar
Expand Down

0 comments on commit 7bb3ae4

Please sign in to comment.