hyperf / hyperf/database-pgsql

pgsql-swoole driver can not prompt errors

未關閉
#9 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
12
分支
3
PR 合併指標
30 天內沒有已合併 PR

描述

## app/Controller/TestController.php
```php
#[RequestMapping(path: "create", methods: "get")]
public function create(ResponseInterface $response)
{
$s = \App\Model\Session::create([
'id' => '131',
'store_id' => 111,
'uuid' => 'abc',
'visitor_id' => '321',
'user_id' => '0',
'fingerprint' => '11111111111',
'client_ip' => '127.0.0.1',
]);
var_dump($s);
return $response->raw('create session');
}
```
## pgsql 日志
```bash
2023-04-23 13:43:37.125 CST,"track","track",46662,"172.17.0.3:36156",6444c589.b646,7,"PARSE",2023-04-23 13:43:37 CST,3/48,0,LOG,00000,"duration: 1.488 ms parse swoole_stmt_2: insert into ""sessions"" (""id"", ""store_id"", ""uuid"", ""visitor_id"", ""user_id"", ""fingerprint"", ""client_ip"", ""updated_at_gmt"", ""created_at_gmt"") values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",,,,,,,,,"","client backend",,0
2023-04-23 13:43:37.127 CST,"track","track",46662,"172.17.0.3:36156",6444c589.b646,8,"BIND",2023-04-23 13:43:37 CST,3/49,0,LOG,00000,"duration: 0.839 ms bind swoole_stmt_2: insert into ""sessions"" (""id"", ""store_id"", ""uuid"", ""visitor_id"", ""user_id"", ""fingerprint"", ""client_ip"", ""updated_at_gmt"", ""created_at_gmt"") values ($1, $2, $3, $4, $5, $6, $7, $8, $9)","parameters: $1 = '131', $2 = '111', $3 = 'abc', $4 = '321', $5 = '0', $6 = '11111111111', $7 = '127.0.0.1', $8 = '2023-04-23 05:43:37', $9 = '2023-04-23 05:43:37'",,,,,,,,"","client backend",,0
2023-04-23 13:43:37.127 CST,"track","track",46662,"172.17.0.3:36156",6444c589.b646,9,"INSERT",2023-04-23 13:43:37 CST,3/49,0,LOG,00000,"execute swoole_stmt_2: insert into ""sessions"" (""id"", ""store_id"", ""uuid"", ""visitor_id"", ""user_id"", ""fingerprint"", ""client_ip"", ""updated_at_gmt"", ""created_at_gmt"") values ($1, $2, $3, $4, $5, $6, $7, $8, $9)","parameters: $1 = '131', $2 = '111', $3 = 'abc', $4 = '321', $5 = '0', $6 = '11111111111', $7 = '127.0.0.1', $8 = '2023-04-23 05:43:37', $9 = '2023-04-23 05:43:37'",,,,,,,,"","client backend",,0
2023-04-23 13:43:37.128 CST,"track","track",46662,"172.17.0.3:36156",6444c589.b646,10,"INSERT",2023-04-23 13:43:37 CST,3/49,1052,ERROR,23505,"duplicate key value violates unique constraint ""sessions_pkey""","Key (store_id, uuid)=(111, abc) already exists.",,,,,"insert into ""sessions"" (""id"", ""store_id"", ""uuid"", ""visitor_id"", ""user_id"", ""fingerprint"", ""client_ip"", ""updated_at_gmt"", ""created_at_gmt"") values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",,,"","client backend",,0
```
## 响应结果
![image](https://user-images.githubusercontent.com/29323350/233822978-44b3c6e6-e714-4158-a7a6-e30adfd70722.png)

## 问题
当我的数据库驱动使用 `pgsql-swoole` 并使用 `model` 去创建新的数据时,无论写入的 SQL 在数据库里是否发生了错误。 model 总能返回一个正确的对象给我,但 pgsql 里却没有对应的数据。

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

Start with app/Controller/TestController.php and the Session::create call, then compare its returned object with the PostgreSQL error shown for the duplicate key. Reproduce the insert using the pgsql-swoole driver and trace how the database error reaches the model. Done means failed inserts surface an error instead of returning a successful-looking object.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
php, postgresql
領域
backend, database
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。