This commit is contained in:
2025-12-31 00:19:29 +08:00
parent c943d6258b
commit 89d5b604d6
5 changed files with 26 additions and 18 deletions
+1 -1
View File
@@ -575,7 +575,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
}
$validate = $this->resolve($rule);
if (!$validate->validation($params)) {
return \Kiri::getLogger()->failure($validate->getError() . PHP_EOL, 'mysql');
return \Kiri::getLogger()->logCategory($validate->getError() . PHP_EOL, 'mysql');
} else {
return TRUE;
}
+2 -2
View File
@@ -41,7 +41,7 @@ class Collection extends AbstractCollection
public function update(array $attributes): bool
{
if ($this->isEmpty()) {
return $this->getLogger()->failure('No data by update', 'mysql');
return $this->getLogger()->logCategory('No data by update', 'mysql');
}
return $this->batch()->update($attributes);
}
@@ -150,7 +150,7 @@ class Collection extends AbstractCollection
{
$model = $this->getModel();
if ($this->isEmpty()) {
return $this->getLogger()->failure('No data by delete', 'mysql');
return $this->getLogger()->logCategory('No data by delete', 'mysql');
}
if (!$model->hasPrimary()) {
throw new Exception('Must set primary key. if you want to delete data');
+10 -6
View File
@@ -123,13 +123,15 @@ class Command extends Component
return $result;
} catch (Throwable $throwable) {
$this->getLogger()->failure(throwable($throwable), 'mysql');
$this->getLogger()->json_log($throwable);
if ($this->isRefresh($throwable)) return $this->search($method);
if ($this->isRefresh($throwable)) {
return $this->search($method);
}
$errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params);
return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql');
return $this->getLogger()->logCategory($errorMsg . PHP_EOL, 'mysql');
} finally {
$this->connection->release($client);
}
@@ -169,13 +171,15 @@ class Command extends Component
return $result == 0 ? $prepare->rowCount() : (int)$result;
} catch (Throwable $throwable) {
$this->getLogger()->failure(throwable($throwable), 'mysql');
$this->getLogger()->json_log($throwable);
if ($this->isRefresh($throwable)) return $this->_prepare();
if ($this->isRefresh($throwable)) {
return $this->_prepare();
}
$errorMsg = $throwable->getMessage() . PHP_EOL . ' Sql: ' . $this->sql . '.' . json_encode($this->params);
return $this->getLogger()->failure($errorMsg . PHP_EOL, 'mysql');
return $this->getLogger()->logCategory($errorMsg . PHP_EOL, 'mysql');
} finally {
$this->connection->release($client);
}
+10 -7
View File
@@ -116,8 +116,9 @@ class Model extends Base\Model
$connection->commit();
return $select;
} catch (\Throwable $throwable) {
$connection->rollback();
return \Kiri::getLogger()->failure($throwable);
$model->getLogger()->json_log($throwable);
$connection->rollback();
return false;
}
}
@@ -145,8 +146,9 @@ class Model extends Base\Model
$connection->commit();
return $select;
} catch (\Throwable $throwable) {
$connection->rollback();
return \Kiri::getLogger()->failure($throwable);
$model->getLogger()->json_log($throwable);
$connection->rollback();
return false;
}
}
@@ -206,9 +208,10 @@ class Model extends Base\Model
public static function inserts(array $data): bool
{
if (empty($data)) {
return trigger_print_error('Insert data empty.', 'mysql');
}
return static::query()->insert($data);
return \Kiri::getLogger()->logCategory('Insert data empty.', 'mysql');
} else {
return static::query()->insert($data);
}
}
/**
+3 -2
View File
@@ -108,7 +108,7 @@ class SqlBuilder extends Component
private function __updateBuilder(array $string): string|bool
{
if (empty($string)) {
return Kiri::getLogger()->failure('None data update.');
return Kiri::getLogger()->logCategory('None data update.');
}
return 'UPDATE ' . $this->query->getFrom() . ' SET ' . implode(',', $string) . $this->make();
}
@@ -452,7 +452,8 @@ class SqlBuilder extends Component
}
} catch (\Throwable $e) {
// 忽略错误,返回默认值
}
$this->getLogger()->json_log($e);
}
// 默认返回 mysql
return 'mysql';
}