mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +00:00
refactor:获取表主键字段接口支持多数据库
This commit is contained in:
parent
360688a8ab
commit
da2ae8122b
@ -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]);
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user