feat: implement database schema discovery and management services with frontend integration

This commit is contained in:
Ümit Tunç
2026-04-24 13:46:38 +03:00
parent 53b40e95e5
commit a447d5a08e
8 changed files with 372 additions and 11 deletions
@@ -302,4 +302,41 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
return $this->query($sql, [$database]);
}
public function batchUpdate(string $table, array $changes): bool
{
$connection = $this->getConnection();
// Find primary key
$schema = $this->getTableSchema($table);
$primaryKey = 'id'; // default
foreach ($schema as $col) {
if (($col->Key ?? '') === 'PRI') {
$primaryKey = $col->Field;
break;
}
}
$connection->beginTransaction();
try {
foreach ($changes as $change) {
if (!isset($change[$primaryKey])) {
continue;
}
$id = $change[$primaryKey];
$updateData = $change;
unset($updateData[$primaryKey]);
if (empty($updateData)) continue;
$connection->table($table)->where($primaryKey, $id)->update($updateData);
}
$connection->commit();
return true;
} catch (\Exception $e) {
$connection->rollBack();
throw $e;
}
}
}