Skip to content

Commit c9b1fc3

Browse files
committed
Remove name from database structure
1 parent 692faa8 commit c9b1fc3

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

src/Tqdev/PhpCrudApi/Column/Reflection/ReflectedDatabase.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55

66
class ReflectedDatabase implements \JsonSerializable
77
{
8-
private $name;
98
private $tableTypes;
109

11-
public function __construct(String $name, array $tableTypes)
10+
public function __construct(array $tableTypes)
1211
{
13-
$this->name = $name;
1412
$this->tableTypes = $tableTypes;
1513
}
1614

1715
public static function fromReflection(GenericReflection $reflection): ReflectedDatabase
1816
{
19-
$name = $reflection->getDatabaseName();
2017
$tableTypes = [];
2118
foreach ($reflection->getTables() as $table) {
2219
$tableName = $table['TABLE_NAME'];
@@ -26,19 +23,13 @@ public static function fromReflection(GenericReflection $reflection): ReflectedD
2623
}
2724
$tableTypes[$tableName] = $tableType;
2825
}
29-
return new ReflectedDatabase($name, $tableTypes);
26+
return new ReflectedDatabase($tableTypes);
3027
}
3128

3229
public static function fromJson( /* object */$json): ReflectedDatabase
3330
{
34-
$name = $json->name;
3531
$tableTypes = (array) $json->tables;
36-
return new ReflectedDatabase($name, $tableTypes);
37-
}
38-
39-
public function getName(): String
40-
{
41-
return $this->name;
32+
return new ReflectedDatabase($tableTypes);
4233
}
4334

4435
public function hasTable(String $tableName): bool
@@ -68,7 +59,6 @@ public function removeTable(String $tableName): bool
6859
public function serialize()
6960
{
7061
return [
71-
'name' => $this->name,
7262
'tables' => $this->tableTypes,
7363
];
7464
}

src/Tqdev/PhpCrudApi/Controller/ColumnController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ public function __construct(Router $router, Responder $responder, ReflectionServ
3232

3333
public function getDatabase(Request $request): Response
3434
{
35-
$name = $this->reflection->getDatabaseName();
3635
$tables = [];
3736
foreach ($this->reflection->getTableNames() as $table) {
3837
$tables[] = $this->reflection->getTable($table);
3938
}
40-
$database = ['name' => $name, 'tables' => $tables];
39+
$database = ['tables' => $tables];
4140
return $this->responder->success($database);
4241
}
4342

tests/functional/003_columns/001_get_database.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ GET /columns
22
===
33
200
44
Content-Type: application/json
5-
Content-Length: 2578
5+
Content-Length: 2556
66

7-
{"name":"php-crud-api","tables":[{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]},{"name":"categories","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","type":"table","columns":[{"name":"id","type":"bigint","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255}]},{"name":"countries","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp"},{"name":"visitors","type":"integer"}]},{"name":"kunsthåndværk","type":"table","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"},{"name":"user_id","type":"integer","fk":"users"}]},{"name":"nopk","type":"table","columns":[{"name":"id","type":"varchar","length":36}]},{"name":"post_tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tag_usage","type":"view","columns":[{"name":"name","type":"varchar","length":255},{"name":"count","type":"bigint"}]},{"name":"tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}
7+
{"tables":[{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]},{"name":"categories","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"icon","type":"blob","nullable":true}]},{"name":"comments","type":"table","columns":[{"name":"id","type":"bigint","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"message","type":"varchar","length":255}]},{"name":"countries","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"shape","type":"geometry"}]},{"name":"events","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"datetime","type":"timestamp"},{"name":"visitors","type":"integer"}]},{"name":"kunsthåndværk","type":"table","columns":[{"name":"id","type":"varchar","length":36,"pk":true},{"name":"Umlauts ä_ö_ü-COUNT","type":"integer"},{"name":"user_id","type":"integer","fk":"users"}]},{"name":"nopk","type":"table","columns":[{"name":"id","type":"varchar","length":36}]},{"name":"post_tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"post_id","type":"integer","fk":"posts"},{"name":"tag_id","type":"integer","fk":"tags"}]},{"name":"posts","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"user_id","type":"integer","fk":"users"},{"name":"category_id","type":"integer","fk":"categories"},{"name":"content","type":"varchar","length":255}]},{"name":"products","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"price","type":"decimal","precision":10,"scale":2},{"name":"properties","type":"clob"},{"name":"created_at","type":"timestamp"},{"name":"deleted_at","type":"timestamp","nullable":true}]},{"name":"tag_usage","type":"view","columns":[{"name":"name","type":"varchar","length":255},{"name":"count","type":"bigint"}]},{"name":"tags","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"name","type":"varchar","length":255},{"name":"is_important","type":"boolean"}]},{"name":"users","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"username","type":"varchar","length":255},{"name":"password","type":"varchar","length":255},{"name":"location","type":"geometry","nullable":true}]}]}

0 commit comments

Comments
 (0)