refactor:获取表主键字段接口支持多数据库

This commit is contained in:
2368302435@qq.com 2024-03-01 19:14:56 +08:00
parent 360688a8ab
commit da2ae8122b
2 changed files with 9 additions and 5 deletions

View File

@ -86,20 +86,23 @@ class Ajax extends Backend
/**
* 获取表主键字段
* @param ?string $table
* @param ?string $connection
* @throws Throwable
*/
public function getTablePk(?string $table = null): void
public function getTablePk(?string $table = null, ?string $connection = null): void
{
if (!$table) {
$this->error(__('Parameter error'));
}
$table = TableManager::tableName($table);
if (!TableManager::phinxAdapter(false)->hasTable($table)) {
$table = TableManager::tableName($table, true, $connection);
if (!TableManager::phinxAdapter(false, $connection)->hasTable($table)) {
$this->error(__('Data table does not exist'));
}
$tablePk = Db::table($table)->getPk();
$tablePk = Db::connect(TableManager::getConnection($connection))
->table($table)
->getPk();
$this->success('', ['pk' => $tablePk]);
}

View File

@ -245,12 +245,13 @@ export function checkClickCaptcha(id: string, info: string, unset: boolean) {
)
}
export function getTablePk(table: string) {
export function getTablePk(table: string, connection = '') {
return createAxios({
url: getTablePkUrl,
method: 'get',
params: {
table: table,
connection: connection,
},
})
}