feat: initialize backend database service architecture and implement frontend schema explorer components

This commit is contained in:
Ümit Tunç
2026-04-24 07:31:24 +03:00
parent ce67df1067
commit bf3d05ea97
13 changed files with 366 additions and 71 deletions
@@ -24,6 +24,11 @@ interface DatabaseDriverInterface
*/
public function getTableData(string $table, int $limit = 100, int $offset = 0): array;
/**
* Get the count of rows in a table.
*/
public function getTableCount(string $table): int;
/**
* Get the underlying connection instance.
*/
@@ -65,9 +65,21 @@ class SchemaController extends Controller
{
try {
$this->initializeDriver($request);
$limit = $request->get('limit', 100);
$offset = $request->get('offset', 0);
return Response::json($this->databaseService->getTableData($table, $limit, $offset));
$skip = $request->get('skip', 0);
$take = $request->get('take', 100);
$data = $this->databaseService->getTableData($table, $take, $skip);
$response = [
'data' => $data,
];
if ($request->get('requireTotalCount') === 'true') {
$response['totalCount'] = $this->databaseService->getTableCount($table);
}
return Response::json($response);
} catch (\Exception $e) {
return Response::json(['error' => $e->getMessage()], 400);
}
@@ -69,6 +69,12 @@ class MySqlDriver implements DatabaseDriverInterface, SchemaDiscoveryInterface
return $this->query("SELECT * FROM `{$table}` LIMIT ? OFFSET ?", [$limit, $offset]);
}
public function getTableCount(string $table): int
{
$result = $this->query("SELECT COUNT(*) as count FROM `{$table}`");
return (int) ($result[0]->count ?? 0);
}
public function getForeignKeys(string $table): array
{
$sql = "
+8
View File
@@ -82,4 +82,12 @@ class DatabaseService
{
return $this->getDriver()->getTableData($table, $limit, $offset);
}
/**
* Get table row count.
*/
public function getTableCount(string $table): int
{
return $this->getDriver()->getTableCount($table);
}
}