Skip to content

Commit 7bb3ae4

Browse files
authored
Optimized the database exception to implement unique constraint error detection. (#7194)
1 parent 725e7a4 commit 7bb3ae4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/PostgreSqlConnection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hyperf\Database\PgSQL;
1414

15+
use Exception;
1516
use Hyperf\Database\Connection;
1617
use Hyperf\Database\PgSQL\DBAL\PostgresDriver;
1718
use Hyperf\Database\PgSQL\Query\Grammars\PostgresGrammar as QueryGrammar;
@@ -48,6 +49,16 @@ public function bindValues(PDOStatement $statement, array $bindings): void
4849
}
4950
}
5051

52+
/**
53+
* Determine if the given database exception was caused by a unique constraint violation.
54+
*
55+
* @return bool
56+
*/
57+
protected function isUniqueConstraintError(Exception $exception)
58+
{
59+
return $exception->getCode() === '23505';
60+
}
61+
5162
/**
5263
* Get the default query grammar instance.
5364
* @return PostgresGrammar

0 commit comments

Comments
 (0)