This commit is contained in:
xl
2023-07-13 10:37:14 +08:00
parent 9d7605b8e4
commit 83138dbcb4
2 changed files with 243 additions and 227 deletions
+2 -3
View File
@@ -209,9 +209,8 @@ class Command extends Component
*/ */
private function error(Throwable $throwable): bool private function error(Throwable $throwable): bool
{ {
error($this->sql . '.' . json_encode($this->params, JSON_UNESCAPED_UNICODE)); $message = $this->sql . '.' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . PHP_EOL . jTraceEx($throwable);
error(throwable($throwable), []); return addError($message, 'mysql');
return addError($throwable->getMessage(), 'mysql');
} }
+20 -3
View File
@@ -227,13 +227,30 @@ class Db implements ISqlBuilder
} }
/**
* @param string $table
* @param Connection|null $connection
* @param string $database
* @return array|null
* @throws Exception
*/
public static function desc(string $table, ?Connection $connection = null, string $database = 'db'): ?array
{
$sql = SqlBuilder::builder(new Query())->columns($table);
$connection = self::getDefaultConnection($connection, $database);
return $connection->createCommand($sql)->all();
}
/** /**
* @param null|Connection $connection * @param null|Connection $connection
* @param string $name * @param string $database
* @return mixed * @return mixed
* @throws Exception * @throws Exception
*/ */
public static function getDefaultConnection(?Connection $connection = null, string $name = 'db'): Connection public static function getDefaultConnection(?Connection $connection = null, string $database = 'db'): Connection
{ {
if ($connection instanceof Connection) { if ($connection instanceof Connection) {
return $connection; return $connection;
@@ -242,7 +259,7 @@ class Db implements ISqlBuilder
if (empty($databases) || !is_array($databases)) { if (empty($databases) || !is_array($databases)) {
throw new Exception('Please configure the database link.'); throw new Exception('Please configure the database link.');
} }
return Kiri::service()->get($databases[$name]); return Kiri::service()->get($databases[$database]);
} }